private void loadLanguages() { mLocaleAdapter = com.android.internal.app.LocalePicker.constructAdapter( getActivity(), R.layout.locale_picker_item, R.id.locale); mInitialLocale = Locale.getDefault(); mCurrentLocale = mInitialLocale; mAdapterIndices = new int[mLocaleAdapter.getCount()]; int currentLocaleIndex = 0; String[] labels = new String[mLocaleAdapter.getCount()]; for (int i = 0; i < mAdapterIndices.length; i++) { com.android.internal.app.LocalePicker.LocaleInfo localLocaleInfo = mLocaleAdapter.getItem(i); Locale localLocale = localLocaleInfo.getLocale(); if (localLocale.equals(mCurrentLocale)) { currentLocaleIndex = i; } mAdapterIndices[i] = i; labels[i] = localLocaleInfo.getLabel(); } mLanguagePicker.setDisplayedValues(labels); mLanguagePicker.setMaxValue(labels.length - 1); mLanguagePicker.setValue(currentLocaleIndex); mLanguagePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); mLanguagePicker.setOnValueChangedListener( new LocalePicker.OnValueChangeListener() { public void onValueChange(LocalePicker picker, int oldVal, int newVal) { setLocaleFromPicker(); } }); }
public void run() { if (mCurrentLocale != null) { com.android.internal.app.LocalePicker.updateLocale(mCurrentLocale); } }