Get date from datepicker using dialogfragment

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 … Read more

Set Limit on the DatePickerDialog in Android?

All the other answers seem rather convoluted, so I’m just going to state the obvious: you can get the underlying DatePicker from a DatePickerDialog (by simply calling getDatePicker()) and set its bounds using: setMinDate(long minDate) setMaxDate(long maxDate) Where the argument is the usual number of milliseconds since January 1, 1970 00:00:00 in the default time … Read more

Jelly Bean DatePickerDialog — is there a way to cancel?

Note: Fixed as of Lollipop, source here. Automated class for use in clients (compatible with all Android versions) updated as well. TL;DR: 1-2-3 dead easy steps for a global solution: Download this class. Implement OnDateSetListener in your activity (or change the class to suit your needs). Trigger the dialog with this code (in this sample, … Read more

Datepicker: How to popup datepicker when click on edittext

Try this in the XML file: <EditText android:id=”@+id/Birthday” custom:font=”@string/font_avenir_book” android:clickable=”false” android:cursorVisible=”false” android:focusable=”false” android:focusableInTouchMode=”false” android:hint=”@string/birthday”/> And this in the Java File: public class MainActivity extends AppCompatActivity { final Calendar myCalendar= Calendar.getInstance(); EditText editText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText=(EditText) findViewById(R.id.BirthDate); DatePickerDialog.OnDateSetListener date =new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int … Read more