android - 如何从 CalendarView 中提取日期并显示所选日期?

标签 android

目前我正在使用下面的代码,我可以获得在文本字段中显示的当前日期。但是我不知道如何显示选定的日期。

我还使用了 DatePicker,它可以很好地显示选定的日期,但我更喜欢 CalendarView。谢谢

Calendar c = Calendar.getInstance();
        SimpleDateFormat ss = new SimpleDateFormat("dd-MM-yyyy");
        Date date = new Date();
        String currentdate= ss.format(date);
        TextView editText = (TextView) this.findViewById(R.id.textfield1);
        editText.setText(currentdate);

最佳答案

在 onCreate 中:

 CalendarView v = new CalendarView( this );
 v.setOnDateChangeListener( new CalendarView.OnDateChangeListener() {
    public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
       this.calendar = new GregorianCalendar( year, month, dayOfMonth );
    }//met
 });

关于android - 如何从 CalendarView 中提取日期并显示所选日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10339808/

相关文章:

android - 如何在 Android Studio 中禁用 RTL 支持(编辑源代码)?

android - Settings.Secure.ANDROID_ID 在每台设备上始终相同

android - 将数据传递给 Android Compose 中的前一个可组合对象

android - 更改editText提示的字体

android - 图形断断续续

android - 在底部显示广告而不与 ListView 重叠

android - 需要始终删除 Firebase 监听器吗?

android - 从 Android 应用程序打开 Gmail

android - 如何在不调用 api 的情况下显示数据?

java - 比较 Hashmap 和 Edittext 的 double 值时遇到问题