1) When you click on a datapicker for a selection, a dialog pops up in which the date is current and not set in TextView . Method in the documentation did not find something. I explain: I choose the year 2000, everything is displayed, I click again and I want to push back from 2000, not 2017 again. This is necessary for convenience when I click on certain years in a row and get results over the network.
Made on the basis of dialogue fragment. In activation, the result is sent through kalbek.
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { DialogFragmentListener mCallback; Boolean timesCalled = true; // Используется как костыль. при нажатии на DataPiker он вызывается дважды. @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); final Calendar calendarMin = Calendar.getInstance(); // Дата для установки нижнего порога в DataPiker calendarMin.set(1999, 0, 1); // http://fixer.io/ хранит курсы валют начиная с 1999 года . Отсчет месяцев идет с нуля. DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), this, year, month, day); DatePicker dp = datePickerDialog.getDatePicker(); dp.setMinDate(calendarMin.getTimeInMillis()); // ставим нижний диапазон в DatePiker dp.setMaxDate(System.currentTimeMillis()); // верхний диапазон в DatePiker устанавливаем сегодняшним днем return datePickerDialog; } @Override public void onDateSet(DatePicker view, int year, int month, int day) { if (timesCalled == true) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String formattedDate = sdf.format(calendar.getTime()); mCallback.getDate(formattedDate); timesCalled = false; } } interface DialogFragmentListener { //узнать зачем нужен вложенный интерфейс void getDate(String date); } @Override public void onAttach(Activity activity) { super.onAttach(activity); try { mCallback = (DialogFragmentListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement DialogFragmentListener"); } } @Override public void onDetach() { super.onDetach(); timesCalled = true; // возвращаем исходное значение mCallback = null; } } The method that takes kalbek in activi
public void getDate(String date) { Current_Date.setText(date); }