I want to set two different Date(s) to two different EditText(s) using datePickerDialog. i am using two different String objects to store date and then setting them on two different EditText(s) respectively but the problem is both the EditText(s) are taking same values.
protected Dialog onCreateDialog(int id) {
// Get the calander
java.util.Calendar c = java.util.Calendar.getInstance();
// From calander get the year, month, day, hour, minute
int year = c.get(java.util.Calendar.YEAR);
int month = c.get(java.util.Calendar.MONTH);
int day = c.get(java.util.Calendar.DAY_OF_MONTH);
switch (id) {
case Date_from:
// Open the datepicker dialog
return new DatePickerDialog(WastageRecordsByDateActivity.this, date_listener, year,
month, day);
case Date_to:
return new DatePickerDialog(WastageRecordsByDateActivity.this, date_listener, year,
month, day);
}
return null;
}
// Date picker dialog
DatePickerDialog.OnDateSetListener date_listener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
// store the data in one string and set it to edittext
String date1 = String.valueOf(day) + "-" + String.valueOf(month + 1)
+ "-" + String.valueOf(year);
editTextFrom.setText(date1);
String date2 = String.valueOf(day) + "-" + String.valueOf(month + 1)
+ "-" + String.valueOf(year);
editTextTo.setText(date2);
}
};
}