반응형
값 중 하나에 ListPreference를 초기화하는 방법
defaultValue를 ListPreference 항목으로 설정하려고합니다.
다음은 내 preference.xml 파일의 샘플입니다.
<ListPreference android:key="notification_delay"
android:title="@string/settings_push_delay"
android:entries="@array/settings_push_delay_human_value"
android:entryValues="@array/settings_push_delay_phone_value"
android:defaultValue="????">
</ListPreference>
두 배열 :
<string-array name="settings_push_delay_human_value">
<item>every 5 minutes</item>
<item>every 10 minutes</item>
<item>every 15 minutes</item>
</string-array>
<string-array
name="settings_push_delay_phone_value">
<item>300</item>
<item>600</item>
<item>900</item>
</string-array>
환경 설정 활동으로 이동할 때 ListPreference의 항목이 선택되지 않았습니다. "android : defaultValue"에서 1과 같은 int 값을 설정하여 "10 분"을 선택하려고했지만 작동하지 않습니다.
<ListPreference android:key="notification_delay"
android:title="@string/settings_push_delay"
android:entries="@array/settings_push_delay_human_value"
android:entryValues="@array/settings_push_delay_phone_value"
android:defaultValue="1">
</ListPreference>
어떤 아이디어?
값 을 지정해야 합니다 . 따라서 기본적으로 선택된 첫 번째 항목을 얻으 defaultValue="300"려면 예제에서 지정 하십시오.
같은 상황에 처하게되었습니다. 일관된 기본값 지정. 그러나 그래픽으로 선택되지 않았습니다. 응용 프로그램 데이터를 지 웠습니다. 그리고 예상대로 작동했습니다. 따라서 새로운 XxxPreference 항목을 추가 할 때 개발 시간에 클리어가 유용 할 수 있습니다.
Sven의 답변 외에도 시작 활동에서 setDefaultValues () 메서드를 호출해야합니다. 이것은 모든 기본값을 한 번 설정합니다.
public class MainActivity extends Activity {
protected void onCreate(final Bundle savedInstanceState) {
// Set all default values once for this application
// This must be done in the 'Main' first activity
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
...
}
}
목록에서 유효한 값이면 앱을 다시 설치하십시오. 작동합니다.
참고 URL : https://stackoverflow.com/questions/3770100/how-to-init-a-listpreference-to-one-of-its-values
반응형
'Program Club' 카테고리의 다른 글
| strncpy가 null이 아닌 이유는 무엇입니까? (0) | 2020.10.29 |
|---|---|
| Spring Security는 Spring 컨트롤러 메서드에서 @PreAuthorize를 사용할 수 있습니까? (0) | 2020.10.29 |
| C ++로 간단한 Qt 콘솔 애플리케이션을 어떻게 생성합니까? (0) | 2020.10.29 |
| CSS box-shadow 숨김 (z-index는 수정되지 않음) (0) | 2020.10.29 |
| Java에서 선언과 정의의 차이점은 무엇입니까? (0) | 2020.10.29 |