Note that there are some explanatory texts on larger screens.

plurals
  1. POSet date of datepickerdialog from EditText
    primarykey
    data
    text
    <p>I am very much surprised that I couldn't find this in net even after 1 hour searching!</p> <p>I have a date picker dialog slightly modified from the original Pickers example (thanks to Raghunandan <a href="https://stackoverflow.com/a/18212061/1951418">for this</a>). </p> <p>But I do not want to set the default date as current date, rather it should pick the date from EditText and set that date to datepickerdialog. Can anybody please help me solving this? My current code stands as below.</p> <p><strong><em>EDITED</strong> I need to know how I can access the value of EditText datepurchased from inside DatePickerFragment class.</em></p> <p>MAIN CLASS:</p> <pre><code>public class EditEntry extends Activity implements DatePickerFragment.TheListener{ EditText edit_datepurchased; public void showdate(View v) { edit_datepurchased = (EditText) findViewById(v.getId()); DialogFragment newFragment = new DatePickerFragment(); newFragment.show(getFragmentManager(), "datePicker"); } public void returnDate(String date) { edit_datepurchased.setText(date); } } </code></pre> <p>DatePickerFragment CLASS:</p> <pre><code>public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { TheListener listener; public interface TheListener{ public void returnDate(String date); } @Override public Dialog onCreateDialog(Bundle savedInstanceState){ final Calendar c=Calendar.getInstance(); int year=c.get(Calendar.YEAR); int month=c.get(Calendar.MONTH); int day=c.get(Calendar.DAY_OF_MONTH); listener = (TheListener) getActivity(); return new DatePickerDialog(getActivity(), this, year, month, day); } public void onDateSet(DatePicker view, int year, int month, int day){ Calendar c = Calendar.getInstance(); c.set(year, month, day); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String formattedDate = sdf.format(c.getTime()); if (listener != null) { listener.returnDate(formattedDate); } //listener.returnDate(year+"-"+(month+1)+"-"+day); } } </code></pre> <p>n.b.: I have a question <a href="https://stackoverflow.com/questions/19891242/copy-selected-date-from-datepickerdialog-to-edittext-box-in-main-page">here on same code before</a>, but I don't know how to add question in old thread.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload