Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the working code, you have to do some changes according to your code. Like you can add min and max age for child and infant.</p> <pre><code>private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { /* * mYear = year; * mMonth = monthOfYear; * mDay = dayOfMonth; */ if (year &gt; maxYear || monthOfYear &gt; maxMonth &amp;&amp; year == maxYear || dayOfMonth &gt; maxDay &amp;&amp; year == maxYear &amp;&amp; monthOfYear == maxMonth) { view.updateDate(maxYear, maxMonth, maxDay); //you can add toast message here for max year selection } else if (year &lt; minYear || monthOfYear &lt; minMonth &amp;&amp; year == minYear || dayOfMonth &lt; minDay &amp;&amp; year == minYear &amp;&amp; monthOfYear == minMonth) { view.updateDate(minYear, minMonth, minDay); //you can add toast message here for min year selection } else { view.updateDate(year, monthOfYear, dayOfMonth); } } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mPickDate = (Button) findViewById(R.id.pickDate); mPickDate.setOnClickListener(this); final Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); maxYear = mYear - 2;//make a proper condition to change it the based on the child/infant maxMonth = mMonth; maxDay = mDay; minYear = mYear - 12;//make a proper condition to change it the based on the child/infant minMonth = mMonth; minDay = mDay; } @Override public void onClick(View v) { showDialog(DATE_DIALOG_ID); } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener, mYear - minYear, mMonth, mDay); } return null; } </code></pre>
    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.
    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