8

SpinnerView を無効にした DatePicker があり、現在は CalendarView のみを使用しています。しかし、それは日曜日から始まるので、月曜日を週の最初の日として使用したいと思います。どうすればそれを変更できますか? 初日は電話の設定に依存すると思いましたが、私のスイスの電話ではまだ間違っています...

set メソッドまたは XML コマンドが見つかりません。

<DatePicker
   android:id="@+id/date_picker"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentLeft="true"
   android:layout_alignParentRight="true" />

DatePicker datePicker = (DatePicker)   convertView.findViewById(R.id.date_picker);
datePicker.setSpinnersShown(false);

- - - - - - 編集: - - - - - -

ロケールを変更しようとしました:

Locale.setDefault(Locale.GERMAN);

しかし、それは何も変わりませんでした。だから私は見つけた android-17.android.widget.DatePicker.java を読みました:

public DatePicker(Context context, AttributeSet attrs, int defStyle) {
  //...  
  // initialization based on locale
        setCurrentLocale(Locale.getDefault());
  //...
}


 /**
 * Sets the current locale.
 *
 * @param locale The current locale.
 */
private void setCurrentLocale(Locale locale) {
    if (locale.equals(mCurrentLocale)) {
        return;
    }

    mCurrentLocale = locale;

    mTempDate = getCalendarForLocale(mTempDate, locale);
    mMinDate = getCalendarForLocale(mMinDate, locale);
    mMaxDate = getCalendarForLocale(mMaxDate, locale);
    mCurrentDate = getCalendarForLocale(mCurrentDate, locale);

    mNumberOfMonths = mTempDate.getActualMaximum(Calendar.MONTH) + 1;
    mShortMonths = new String[mNumberOfMonths];
    for (int i = 0; i < mNumberOfMonths; i++) {
        mShortMonths[i] = DateUtils.getMonthString(Calendar.JANUARY + i,
                DateUtils.LENGTH_MEDIUM);
    }
}

 /**
 * Gets a calendar for locale bootstrapped with the value of a given calendar.
 *
 * @param oldCalendar The old calendar.
 * @param locale The locale.
 */
private Calendar getCalendarForLocale(Calendar oldCalendar, Locale locale) {
    if (oldCalendar == null) {
        return Calendar.getInstance(locale);
    } else {
        final long currentTimeMillis = oldCalendar.getTimeInMillis();
        Calendar newCalendar = Calendar.getInstance(locale);
        newCalendar.setTimeInMillis(currentTimeMillis);
        return newCalendar;
    }
}

では、なぜ Locale.setDefault(Locale.GERMAN) が機能しないのでしょうか?! 上記のように、XML から DatePicker を取得しています。間違いはありませんか?!

4

3 に答える 3

16

たとえば、アクティビティ/フラグメントの onCreate()/onCreateView() で、週の最初の曜日を手動で設定する必要があります。

date = (DatePicker) value.findViewById(R.id.date);
if (Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1) {
    date.setSpinnersShown(false);
    date.setCalendarViewShown(true);
    date.getCalendarView().setFirstDayOfWeek(Calendar.getInstance().getFirstDayOfWeek());
}

上記の例では、デフォルトのロケールを使用しています (Calendar.getInstance() は実際に使用しています) が、手動で日を指定できます。

date.getCalendarView().setFirstDayOfWeek(Calendar.MONDAY);
于 2013-01-20T10:16:15.997 に答える
0

これは、デバイスのローカリゼーションによって異なります。

こちらをご覧ください: How to make GWT DatePicker to use Monday as week?

于 2012-11-29T17:26:07.293 に答える