我已经设置了 lp.setDefaultValue("2"),但是当我运行应用程序时,我发现第 2 项没有被选中,为什么?谢谢!
public class PhotoPreference extends PreferenceActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.mypreference);
setContentView(R.layout.photo_preference);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adViewpreference);
adView.loadAd(new AdRequest());
ListPreference lp = (ListPreference)findPreference("SetLastFolder");
CharSequence[] entries = { "One", "Two", "Three" };
CharSequence[] entryValues = { "1", "2", "3" };
lp.setEntries(entries);
lp.setEntryValues(entryValues);
lp.setDefaultValue("2");
}
}
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="AppPreference"
android:summary="@string/Preferencesummary"
android:title="@string/Preference" >
<ListPreference
android:key="SetLastFolder"
android:dialogTitle="@string/SelectGallery"
android:title="@string/SelectGallery"
android:summary="@string/SelectGallerysummary"
android:layout="@layout/photopreference_layout"
/>
</PreferenceScreen>