Tell me please. There is a need to use methods to select a date in the DatePickerDialog for two dates. There is the following code:

public void setDate(View v, Calendar dateSelected) { //отображаем диалоговое окно для выбора даты new DatePickerDialog(getActivity(), datePickerDialogListener(dateSelected), dateToDay.get(Calendar.YEAR), dateToDay.get(Calendar.MONTH), dateToDay.get(Calendar.DAY_OF_MONTH)) .show(); } private DatePickerDialog.OnDateSetListener datePickerDialogListener(Calendar dateSelected) { DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { dateSelected.set(Calendar.YEAR, year); dateSelected.set(Calendar.MONTH, monthOfYear); dateSelected.set(Calendar.DAY_OF_MONTH, dayOfMonth); } }; return d; } 

These methods will be called in the following code:

  @Override public void onClick(View v) { switch (v.getId()) { case R.id.first_date_selected: setDate(v, firstDateSelected); break; case R.id.last_date_selected: setDate(v, lastDateSelected); break; case R.id.button_view: break; } } 

But, the DatePickerDialog.OnDateSetListener method does not work, because I need to declare the passed parameter as static, but I need to label the values ​​in it. How can you make this method allow you to work with a parameter?

  • Not very clear what you want. The listeners return data, not receive. What and why do you want to set up there. - pavlofff
  • The user will select the date of the beginning of the period and the date of the end of the period, I need the code to work for both periods and the dates that were selected by users are listed in the corresponding variables. - Alexander
  • Well, and the listener, it returns the dates entered in the picker, and does not accept them / see this answer , maybe it will be useful to you. - pavlofff
  • Yes, this is exactly what you need. How do you put a plus in karma? - Alexander
  • Well vote for that answer. If that answer completely solves your problem, then I will close this question, as a duplicate of that? - pavlofff

0