簡體   English   中英

在Android中更新CalendarView中的輸入日期

[英]Update entered date in CalendarView in Android

我有一個Calendarview和一個Edittext。 我希望以DD / MM / YYYY格式輸入在編輯文本中輸入的日期,並將其設置在Calendarview上。 視圖應將當前日期氣泡更新為設置的日期。

我已經嘗試過: 如何在CalendarView的特定日期上設置焦點,知道日期是“ dd / mm / yyyy”

這是我當前的代碼:

        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

提前致謝!

我已閱讀您的問題,並已嘗試解決此問題。 以長類型值傳遞日期(以毫秒為單位的時間)以在日歷視圖中設置日期,例如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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM