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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With