【问题标题】:How to select month, year and change the date in calendar view with the help of spinner in android?如何在android中的微调器的帮助下在日历视图中选择月份、年份和更改日期?
【发布时间】:2021-07-21 03:56:18
【问题描述】:

应用程序的要求是 DOB(出生日期) 的自定义日历,用户可以在其中从两个微调器中选择月份和年份,并从日历视图中选择最终日期。 例如:-

First Spinner:- 月份:- 六月

第二次旋转:- 年份:- 1990

自定义日历视图:- 日期:- 23

Textview 中的最终输出:- 1990 年 6 月 23 日

我知道在微调器中设置月份和年份,这是代码,但无法连接日历中的月份和年份。请帮忙

// Set years
        ArrayList<String> years = new ArrayList<String>();
        int thisYear = Calendar.getInstance().get(Calendar.YEAR);
        for (int i = 1900; i <= thisYear; i++) {
            years.add(Integer.toString(i));
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, years);

        Spinner spinYear = (Spinner)findViewById(R.id.spinnerYears);
        spinYear.setAdapter(adapter);
        // Set months
        ArrayAdapter<String> adapterMonths = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, Months);
        adapterMonths.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        Spinner spinMonths = (Spinner)findViewById(R.id.spinnerMonths);
        spinMonths.setAdapter(adapterMonths);

我附上了一张图片,请找到我的附件。我想要与图片中所示完全相同的 UI。

【问题讨论】:

  • 谁能帮帮我?任何人...

标签: android android-spinner android-calendar


【解决方案1】:

这个日历功能有一个现成的 CalendarView 插件,可以直接使用。使用插件来实现这个效果非常方便。 https://github.com/SheHuan/CalendarView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    相关资源
    最近更新 更多