我正在尝试编写一个 Android Honeycomb 应用程序,但在子类化首选项时遇到问题:http: //developer.android.com/reference/android/preference/Preference.html
我想制作一个带有标题和摘要的类似布局,但还有一个进度条。
我已经创建了布局并添加了自定义首选项类,但我似乎无法获取它的实例来设置其中项目的值。
似乎偏好键不适用于自定义类。
这是我与标准偏好类相比的偏好定义:
<Preference
android:key="int_free_storage"
android:title="Free Space"
android:summary="free storage value here"/>
<com.hamid.storageether.SpacePreference
android:key="int_space_test"
android:title="Test"
android:summary="This is my custom preference"/>
然后我的首选子类将我的 XML 布局设置为其构造函数中的布局资源
setLayoutResource(R.layout.space_pref_layout);
它还覆盖了 setTitle 和 setSummary 方法....
在我的主要 PreferenceActivity 中,我尝试通过它的关键来获取我的偏好,但似乎没有运气,因为偏好永远不会更新:
// These Two work
Preference intTotal = (Preference)findPreference("int_total_storage");
Preference intFree = (Preference)findPreference("int_free_storage");
intTotal.setSummary("Standard Preference Summary 1");
intFree.setSummary("Standard Preference Summary 2");
// My subclass doesn't - It just displays the default text defined in the layout xml.
SpacePreference intTest = (SpacePreference)findPreference("int_test_space");
intTest.setTitle("Testtttyyy");
intTest.setSummary("Test Summary");
有人可以指出我可能出错的地方吗?