我正在使用ActionBarSherlock
. 我的问题是制作偏好屏幕。类上的onBuildHeader()
方法SherlockPreferenceActivity
是神经调用。
这是我的代码
首选项_headers.xml
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >
<header
android:fragment="package.fragments.MyPreferenceFragment"
android:icon="@drawable/bulle"
android:summary="An example of some preferences."
android:title="title" />
</preference-headers>
首选项.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/options" >
<PreferenceCategory>
<SwitchPreference
android:id="@+id/cb_notif"
android:defaultValue="false"
android:key="com.vincent.HTC_Dev.pref.notif"
android:summaryOff="@string/notifications_off"
android:summaryOn="@string/notifications_on"
android:title="@string/notifications" />
</PreferenceCategory>
</PreferenceScreen>
我的偏好活动
public class MyPreferenceActivity extends SherlockPreferenceActivity {
@Override
public void onBuildHeaders(List<Header> target) {
super.onBuildHeaders(target);
loadHeadersFromResource(R.xml.preference_headers, target);
}
}
我的偏好片段
public class MyPreferenceFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// TODO Auto-generated method stub
}
}