全部產品
Search
文件中心

Mobile Platform as a Service:日期

更新時間:Oct 21, 2025

AUDatePicker 是一個日期選擇控制項,本質是一個彈窗。

效果圖

介面說明

  /**
     * Instantiates a new Date picker.
     *
     * @param activity the activity
     * @param mode     the mode
     * @see #YEAR_MONTH_DAY #YEAR_MONTH_DAY#YEAR_MONTH_DAY
     * @see #YEAR_MONTH #YEAR_MONTH#YEAR_MONTH
     * @see #MONTH_DAY #MONTH_DAY#MONTH_DAY
     */
    public AUDatePicker(Activity activity, @Mode int mode)

    /**
     * 設定日期範圍
     *
     * @param startYear the start year
     * @param endYear   the end year
     */
    public void setRange(int startYear, int endYear)

··/**
     * 選中指定的年月日
     *
     * @param year  the year
     * @param month the month
     * @param day   the day
     */
    public void setSelectedItem(int year, int month, int day) 

  /**
     * 選中指定的日期
     *
     * @param yearOrMonth the year or month
     * @param monthOrDay  the month or day
     */
    public void setSelectedItem(int yearOrMonth, int monthOrDay)

  /**
     * 設定日期選中的監聽
     *
     * @param listener the listener
     */
    public void setOnDatePickListener(OnDatePickListener listener) {
        this.onDatePickListener = listener;
    }

    /**
     * The interface on year month day pick listener.
     */
    public interface OnYearMonthDayPickListener extends OnDatePickListener {

      /**
         * On date picked.
         *
         * @param year  the year
         * @param month the month
         * @param day   the day
         */
        void onDatePicked(String year, String month, String day);

    }

    /**
     * The interface On year month pick listener.
     */
    public interface OnYearMonthPickListener extends OnDatePickListener {

      /**
         * On date picked.
         *
         * @param year  the year
         * @param month the month
         */
        void onDatePicked(String year, String month);

    }

  /**
     * The interface On month day pick listener.
     */
    public interface OnMonthDayPickListener extends OnDatePickListener {

      /**
         * On date picked.
         *
         * @param month the month
         * @param day   the day
         */
        void onDatePicked(String month, String day);

    }

自訂屬性

無自訂屬性,不支援 XML 布局檔案。

程式碼範例

AUDatePicker datePicker = new AUDatePicker(DatePickActivity.this,AUDatePicker.YEAR_MONTH_DAY);
                datePicker.setRange(1949,2050);
                datePicker.setOnDatePickListener(new AUDatePicker.OnYearMonthDayPickListener() {
                    @Override
                    public void onDatePicked(String year, String month, String day) {
                        Toast.makeText(DatePickActivity.this,year + "-" + month + "-" + day,Toast.LENGTH_LONG).show();
                    }
                });
                datePicker.show();

內嵌頁面的 AUDatePicker 的使用:

AUDatePicker picker = new AUDatePicker(this);
        picker.show();
        picker.dismiss();
        View view = picker.getOutterView();
        LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
        layout.removeAllViews();
        if(view != null) {
            ((ViewGroup) view.getParent()).removeAllViews();
            layout.addView(view);
        }

如有疑問,請搜尋群號 145930007362 加入DingTalk群聯絡技術支援人員擷取協助。