我使用PreferenceActivity,请问如何删除Preference。这个不能正常运行
- Preference p = findPreference("grok");
- boolean worked = getPreferenceScreen().removePreference(p);
- // worked == false.
- <PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android">
- <PreferenceCategory
- android:title="foo">
- <CheckBoxPreference
- android:key="grok" />
- ...
XML:
- <PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android">
- <PreferenceCategory
- android:key="category_foo"
- android:title="foo">
- <CheckBoxPreference
- android:key="grok" />
- ...
Code:
- Preference p = findPreference("grok");
- // removing Preference
- ((PreferenceGroup) findPreference("category_foo")).removePreference(p);
复制代码
原文链接http://stackoverflow.com/questions/9348544/class-extends-listactivity-whose-id-attribute-is-android-r-id-list