Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set date on date picker based on other date picker in android
    primarykey
    data
    text
    <p>I have used below code to generate run time date-picker.</p> <pre><code>public class MultiDatePickerActivity extends Activity { private TextView startDateDisplay; private TextView endDateDisplay; private Button startPickDate; private Button endPickDate; private Calendar startDate; private Calendar endDate; static final int DATE_DIALOG_ID = 0; private TextView activeDateDisplay; private Calendar activeDate; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.multidatepicker); /* capture our View elements for the start date function */ startDateDisplay = (TextView) findViewById(R.id.startDateDisplay); startPickDate = (Button) findViewById(R.id.startPickDate); /* get the current date */ startDate = Calendar.getInstance(); /* add a click listener to the button */ startPickDate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDateDialog(startDateDisplay, startDate); } }); /* capture our View elements for the end date function */ endDateDisplay = (TextView) findViewById(R.id.endDateDisplay); endPickDate = (Button) findViewById(R.id.endPickDate); /* get the current date */ endDate = Calendar.getInstance(); /* add a click listener to the button */ endPickDate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDateDialog(endDateDisplay, endDate); } }); /* display the current date (this method is below) */ updateDisplay(startDateDisplay, startDate); updateDisplay(endDateDisplay, endDate); } private void updateDisplay(TextView dateDisplay, Calendar date) { dateDisplay.setText( new StringBuilder() // Month is 0 based so add 1 .append(date.get(Calendar.MONTH) + 1).append("-") .append(date.get(Calendar.DAY_OF_MONTH)).append("-") .append(date.get(Calendar.YEAR)).append(" ")); } public void showDateDialog(TextView dateDisplay, Calendar date) { activeDateDisplay = dateDisplay; activeDate = date; showDialog(DATE_DIALOG_ID); } private OnDateSetListener dateSetListener = new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { activeDate.set(Calendar.YEAR, year); activeDate.set(Calendar.MONTH, monthOfYear); activeDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); updateDisplay(activeDateDisplay, activeDate); unregisterDateDisplay(); } }; private void unregisterDateDisplay() { activeDateDisplay = null; activeDate = null; } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, dateSetListener, activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH)); } return null; } @Override protected void onPrepareDialog(int id, Dialog dialog) { super.onPrepareDialog(id, dialog); switch (id) { case DATE_DIALOG_ID: ((DatePickerDialog) dialog).updateDate(activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH)); break; } } } </code></pre> <p>I want when i press endDate it should not show current date insted of this i want it check which date i have selected in startDate and it should show next date of startDate in endDate picker.</p> <p>It means i want to set endDate based on startDate (Next date of start date). Say if i today is 12-05-2013 and if i select 15-05-2013 as start date then it should show 16-05-2013 in endDate picker. So how can i achieve this. </p> <p>Please help me. Any help would be appreciated. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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