0

I want to call a method when the user select a date on a datepicker. I don't know how to do that, there is no onDateSet method. Should I use a listener? Please help me.

EDIT: Here's the code regarding the datepicker:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    dp=(DatePicker)findViewById(R.id.dp);

    c = Calendar.getInstance();
    Month =c.get(Calendar.MONTH)+1;
    Day = c.get(Calendar.DAY_OF_MONTH);
    Year = c.get(Calendar.YEAR);
    dp.init(c.get(Calendar.YEAR),(c.get(Calendar.MONTH)+1), Day, null); 

Now, this view is in the main layout of my app, it have no buttons, just the datepicker with rolling number. I want to call a method when the user roll a different number on this datepicker. There is no positive button or any button at all, so the answer wouldn't work for me...

FFP
  • 1
  • 1

1 Answers1

0
_datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {

  public void onClick(DialogInterface arg0, int arg1) {
    _done = true;
    DatePicker datePicker = _datePickerDialog.getDatePicker();
    _datePickerDialogCallback.onDateSet(datePicker, datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
  }

});

here is the link to the original article

Community
  • 1
  • 1
william.eyidi
  • 2,315
  • 4
  • 27
  • 39
  • I think i forgot to mention that i am programming an app for android using eclipse. What is this that you posted? – FFP Jun 01 '15 at 17:58