Get date from datepicker using dialogfragment

前端 未结 9 874
庸人自扰
庸人自扰 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:14

    i have one correction to the above answer. instead of return the DatePickerDialog like this

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

    you should return it in a more generic way

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

    just make sure your activity implements OnDateSetListener interface and override the function onDateSet

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) 
    

提交回复
热议问题