Get date from datepicker using dialogfragment

前端 未结 9 853
庸人自扰
庸人自扰 2020-11-28 03:42

I\'m using the google example to insert a datepicker inside my app using a dialogfragment
http://developer.android.com/guide/topics/ui/controls/pickers.html

But

9条回答
  •  攒了一身酷
    2020-11-28 04:16

    Constructor fo DatePickerDialog takes DatePickerDialog.OnDateSetListener as second parameter, so maybe you should implement that interface in your parent activity EditSessionActivity (not in DatePickerFragment ) and change this line:

    return new DatePickerDialog(getActivity(), this, year, month, day);
    

    into this:

    return new DatePickerDialog(getActivity(), (EditSessionActivity)getActivity(), year, month, day);
    

    And then your activity should looks like this:

    public class EditSessionActivity extends FragmentActivity implements
            DatePickerDialog.OnDateSetListener{
    
        public void onDateSet(DatePicker view, int year, int month, int day) {
            //use date in your activity
        }
        ...
    }
    

提交回复
热议问题