Skip to content

Instantly share code, notes, and snippets.

@devrath
Created November 25, 2014 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devrath/83b8d28e46e9afb179a3 to your computer and use it in GitHub Desktop.
Save devrath/83b8d28e46e9afb179a3 to your computer and use it in GitHub Desktop.
Setting the date in edittext using the date picker with dialog
//*****************CALLL THIS FUNCTION CALL IN ON CLICK OF A VIEW*****************//
selectDate(v);
//*****************CALLL THIS FUNCTION CALL IN ON CLICK OF A VIEW*****************//
//*******Date picker implementation******(Start)***//
public void selectDate(View view) {
DialogFragment fragment = new SelectDateFragment();
fragment.show(getFragmentManager(), "DatePicker");
}
public void populateSetDate(int year, int month, int day) {
edtTxtDateId = (EditText) getActivity().findViewById(R.id.edtTxtDateId);
edtTxtDateId.setText(month+"/"+day+"/"+year);
}
public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}
public void onDateSet(DatePicker view, int yy, int mm, int dd) {
populateSetDate(yy, mm+1, dd);
}
}
//*******Date picker implementation******(End)***//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment