Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog with DatePicker

My idea is to use an AlertDialog and set to it a a DatePicker.
My code is:

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    DatePicker picker = new DatePicker(this);
    picker.setCalendarViewShown(false);

    builder.setTitle("Create Year");
    builder.setView(picker);
    builder.setNegativeButton("Cancel", null);
    builder.setPositiveButton("Set", null);

    builder.show();

it works, but my question is: how can i have the listeners on the set and cancel button?
About the set button i would like to have the listener and (of course) get the date of the user (his date selection)


I want also show just the year so i want to hide the day and month data.

like image 906
Giovanni Far Avatar asked Nov 10 '14 00:11

Giovanni Far


1 Answers

You can use setPositiveButton, like this :

dialog.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int id) {
    //do something         
  }
});

The same for setNegativeButton.

I want also show just the year so i want to hide the day and month data

See this, use the 1st answer :

Hide Year field in Android DatePicker?

like image 129
Blaze Tama Avatar answered Oct 22 '22 21:10

Blaze Tama