3
我做了一個自定義首選項佈局,每行有2個切換,稱爲dualtogglepreference。連同一個擴展Preference的類一起處理它的一些細節。當我將這個自定義首選項添加到我的preferences.xml文件時,它出現在UI中,但我無法在首選項活動中使用findPreference來引用它。在PreferenceActivity中找不到自定義首選項的偏好
的preferences.xml文件
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Notifications">
<com.hitpost.testing.DualTogglePreference
android:key="followsMe"
android:title="Someone follows me"
android:layout="@layout/dualtogglepreference"/>
</PreferenceCategory>
</PreferenceScreen>
PreferenceActivity
public class TestingCustomPreferenceActivity extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
DualTogglePreference followsMe = (DualTogglePreference) findPreference("followsMe");
if (followsMe != null)
Log.e("FOLLOWS_ME", "NOT NULL");
else
Log.e("FOLLOWS_ME", "NULL"); //THIS IS PRINTED
}
}
視覺一切看起來完美的,即對於插件的佈局是正確的。請幫忙,在最後一天一直在爲此奮戰。
您是否將followingMe作爲NULL?我無法準確理解你所遇到的問題。請提供更多信息。 – kosa 2012-01-03 20:05:29
是的followingMe即將到來null – Leo 2012-01-03 20:23:00
我希望你的DualTogglePreference擴展偏好。可能是你可以參考這個鏈接,如果還沒有http://www.java2s.com/Code/Android/Core-Class/Acustompreferencetype這個偏好的數量單擊它已經收到並且存儲從這個收藏中收回.htm – kosa 2012-01-03 20:50:09