I'm using two text views in a dialog, one is for from date and another is for to date. Now when i click on from date text view the date picker dialog opens and when i select the date it is not updated in the text view, if i open the date picker again and select the date for the second time the date is updated in the text view. can any one figure out why it is not updated the first time.
public static void datePickerDialog(final Context context) {
dialog = new Dialog(context);
dialog.setContentView(R.layout.date_picker_dialog);
fromDateText = dialog.findViewById(R.id.from_date);
toDateText = dialog.findViewById(R.id.to_date);
fromDateText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
datePicker(context);
}
});
toDateText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
datePicker(context);
}
});
dialog.show();
fromDateText.setText(fromDate);
toDateText.setText(toDate);
}
public static void datePicker(Context context){
fromDatePicker = new DatePickerDialog(context, android.R.style.Theme_Holo_Light_Dialog_MinWidth
,fromDateListner, fromDay, fromMonth, fromYear);
simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
fromDatePicker.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
fromDatePicker.show();
fromDateListner = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
month+=1;
fromDate = dayOfMonth+"/"+month+"/"+year;
setDate();
}
};
}
private static void setDate() {
try {
dateFrom = simpleDateFormat.parse(fromDate);
dateTo = simpleDateFormat.parse(toDate);
} catch (ParseException e) {
e.printStackTrace();
}
fromDateText.setText(dateFrom.toString());
toDateText.setText(dateTo.toString());
}