Created
November 25, 2014 05:07
-
-
Save devrath/83b8d28e46e9afb179a3 to your computer and use it in GitHub Desktop.
Setting the date in edittext using the date picker with dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*****************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