我的自定义Preference
包含ListView
。我想在PreferenceActivity
中显示它(在同一个屏幕中不在Diaog
中),但它不会填充。我告诉你da代码,哈哈。我的ListPreferences对象它只是一个从Preference
PreferenceActivity:
公共类SettingsActivity扩展了PreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
preference.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:key="themeTitle"
android:title="@string/settings_group_themes">
<com.battleship.preferences.ListPreferences
android:key="theme" android:widgetLayout="@id/listView" />
</PreferenceCategory>
</PreferenceScreen>
list_preference.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView" android:layout_width="wrap_content"
android:choiceMode="singleChoice" android:layout_height="wrap_content"
android:orientation="vertical" android:footerDividersEnabled="true"
android:entries = "@array/themeArray"
/>
arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="themeArray">
<item>Default</item>
<item>Black</item>
<item>White</item>
</string-array>
</resources>