Spinner日期选择器显示日期名称

时间:2017-08-19 05:31:32

标签: android

我需要让我的微调器DatePicker显示日期名称(DAY_OF_WEEK)而不是数字(DAY_OF_MONTH)

目前Spinner显示月份的天数(1,2,3 ... 30),但我希望它也能显示天数(星期日,星期一......)

以下是我的称呼方式:

final DatePickerDialog.OnDateSetListener sessDay = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                              int dayOfMonth) {
            dateCalendar.set(Calendar.YEAR, year);
            dateCalendar.set(Calendar.MONTH, monthOfYear);
            dateCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            pickDayBtn.setText(Q.DATE_FORMAT.format(dateCalendar.getTime()));
        }
    };

dayPickerDialog = new DatePickerDialog(SessionsSettingsActivity.this, R.style.MySpinnerDatePickerStyle, sessDay, dateCalendar
            .get(Calendar.YEAR), dateCalendar.get(Calendar.MONTH),
            dateCalendar.get(Calendar.DAY_OF_MONTH));

这就是我使用的风格:

<style name="MySpinnerDatePickerStyle" parent="android:Theme.Material.Dialog">
    <item name="android:datePickerStyle">@style/MySpinnerDatePicker</item>
</style>

<style name="MySpinnerDatePicker" parent="android:Widget.Material.DatePicker">
    <item name="android:datePickerMode">spinner</item>
    <item name="android:background">@color/colorPrimary</item>
</style>

1 个答案:

答案 0 :(得分:0)

您应该更改日期格式以实现它。以下是示例代码:

SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy");   
Log.e("New Date Format ", String.valueOf(dateFormat.format(newDate.getTime())) + "");    
// Shows  "Saturday, August 19, 2017"

更改日期格式后,您可以override按照自己喜欢的方式spinner