<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Notifications">
<CheckBoxPreference
android:key="vibration"
android:title="Vibrate"
android:summary="Vibrate phone for notifications" />
<CheckBoxPreference
android:key="play_tone"
android:title="Play Ringtone"
android:summary="Play Ringtone for notifications" />
<RingtonePreference
android:key="app_ringtone"
android:dependency="play_tone"
android:title="Select Ringtone"
android:ringtoneType="notification"
android:showDefault="true"
android:shouldDisableView="true"
android:summary="Pick a Ringtone" />
</PreferenceCategory>
</PreferenceScreen>
这是我的偏好XML。但是,RingtonePreference总是空:(
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.getString("app_ringtone", null);
总是返回null。我调试的设备(HTC野火)上。
你怎么知道它是空的?只是在调试器上,或者你真的强制关闭?如果是这样,给我们一个堆栈跟踪。你在getDefaultSharedPreferences或prefs.getString上获得NPE吗? – Falmarri 2010-09-30 16:08:24
看看我所做的prefs.getString(“app_ringtone”,null)调用。 – 2010-09-30 16:24:40
我从** SharedPreferences.getAll().keySet()**中发现,“app_ringtone”键不在第一位。 – 2010-09-30 17:00:30