Обновление введенной даты в CalendarView в Android - PullRequest
1 голос
/ 17 июня 2019

У меня есть просмотр календаря и текст редактирования.Я хочу взять дату, введенную в тексте редактирования в формате ДД / ММ / ГГГГ, и установить ее в режиме просмотра календаря.Представление должно обновить пузырек с текущей датой до установленной даты.

Я уже пробовал: Как установить фокус на конкретную дату в CalendarView, зная дату «дд / мм / гггг»

Это мой текущий код:

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, 2019);
        calendar.set(Calendar.MONTH, Calendar.JUNE);
        calendar.set(Calendar.DAY_OF_MONTH, 20);

        long milliTime = calendar.getTimeInMillis();
        CalendarView calendarView =  findViewById(R.id.calendar);
        calendarView.setFocusedMonthDateColor(Color.BLUE); //apparently this is deprecated so won't work. Not working without it either.
        calendarView.setDate (milliTime); //this is supposed to change the date but isn't

Заранее спасибо!

1 Ответ

0 голосов
/ 20 июня 2019

Я прочитал ваш вопрос и попытался решить эту проблему. передайте дату (время в миллисекундах) в длинном значении типа, чтобы установить дату в представлении календаря, как это calendar_view.setDate(milliTime); попробуйте этот код для достижения своей цели.

Код

    calendar_view = findViewById(R.id.calendar_view);

  //replace date variable static value to your edit text 
    value    
  String date = "25/06/2019";
    String parts[] = date.split("/");

    int day = Integer.parseInt(parts[0]);
    int month = Integer.parseInt(parts[1]);
    int year = Integer.parseInt(parts[2]);

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DAY_OF_MONTH, day);

    long milliTime = calendar.getTimeInMillis();
    calendar_view.setDate(milliTime);
...