当我点击 header 时,没有偏好显示
When i click on header, no preferences show up
我正在为我的应用程序设置 activity。我为首选项设置了两个 header,然后我为每个 header 制作了片段。问题是当我点击 header 时,没有任何显示。感谢您的帮助。
这是我的偏好activity
public class Preferences extends PreferenceActivity {
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.prefheads, target);
}
}
这是第一个片段
public class Prefs1 extends PreferenceFragment {
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.fragment_prefs1);
}
}
}
这是第二个片段:
public class Prefs2 extends PreferenceFragment {
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.fragment_prefs2);
}
}
}
XML 个文件:
Headers
<?xml version="1.0" encoding="utf-8"?>
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<header
android:fragment="com.example.lubys.prefs.prefs1"
android:title="First category"
android:summary="This doesnt need summary" />
<header
android:fragment="com.example.lubys.prefs.prefs2"
android:title="Second cat"
android:summary="This is awful summary">
</header>
</preference-headers>
片段 1:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.lubys.prefs.prefs1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<PreferenceCategory
android:title="the title"
android:key="key2">
<EditTextPreference android:title="Your Name"
android:key="username"
android:summary="Please provide your username"></EditTextPreference>
<CheckBoxPreference android:title="Application Updates"
android:defaultValue="false"
android:summary="This option if selected will allow the application to check for latest versions."
android:key="applicationUpdates" />
<ListPreference
android:title="Download Details"
android:summary="Select the kind of data that you would like to download"
android:key="downloadType"
android:defaultValue="1"
android:entries="@array/c"
android:entryValues="@array/c" />
</PreferenceCategory>
</PreferenceScreen>
片段 2:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.lubys.prefs.prefs1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<PreferenceCategory
android:title="sms"
android:key="pref_key_storage_settings">
<CheckBoxPreference
android:key="saas"
android:summary="asde"
android:title="Something"
android:defaultValue="false"/>
</PreferenceCategory>
</PreferenceScreen>
检查你是否没有得到:
java.lang.RuntimeException:
Subclasses of PreferenceActivity must override isValidFragment(String) to verify that the Fragment class is valid!
XXX has not checked if fragment YYY is valid.
isValidFragment Android API 19
when android's isValidFragment() from PreferenceActivity gets called?
http://securityintelligence.com/new-vulnerability-android-framework-fragment-injection#.VRGSv1V_NBc
我正在为我的应用程序设置 activity。我为首选项设置了两个 header,然后我为每个 header 制作了片段。问题是当我点击 header 时,没有任何显示。感谢您的帮助。
这是我的偏好activity
public class Preferences extends PreferenceActivity {
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.prefheads, target);
}
}
这是第一个片段
public class Prefs1 extends PreferenceFragment {
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.fragment_prefs1);
}
}
}
这是第二个片段:
public class Prefs2 extends PreferenceFragment {
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.fragment_prefs2);
}
}
}
XML 个文件: Headers
<?xml version="1.0" encoding="utf-8"?>
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<header
android:fragment="com.example.lubys.prefs.prefs1"
android:title="First category"
android:summary="This doesnt need summary" />
<header
android:fragment="com.example.lubys.prefs.prefs2"
android:title="Second cat"
android:summary="This is awful summary">
</header>
</preference-headers>
片段 1:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.lubys.prefs.prefs1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<PreferenceCategory
android:title="the title"
android:key="key2">
<EditTextPreference android:title="Your Name"
android:key="username"
android:summary="Please provide your username"></EditTextPreference>
<CheckBoxPreference android:title="Application Updates"
android:defaultValue="false"
android:summary="This option if selected will allow the application to check for latest versions."
android:key="applicationUpdates" />
<ListPreference
android:title="Download Details"
android:summary="Select the kind of data that you would like to download"
android:key="downloadType"
android:defaultValue="1"
android:entries="@array/c"
android:entryValues="@array/c" />
</PreferenceCategory>
</PreferenceScreen>
片段 2:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.lubys.prefs.prefs1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<PreferenceCategory
android:title="sms"
android:key="pref_key_storage_settings">
<CheckBoxPreference
android:key="saas"
android:summary="asde"
android:title="Something"
android:defaultValue="false"/>
</PreferenceCategory>
</PreferenceScreen>
检查你是否没有得到:
java.lang.RuntimeException:
Subclasses of PreferenceActivity must override isValidFragment(String) to verify that the Fragment class is valid! XXX has not checked if fragment YYY is valid.
isValidFragment Android API 19
when android's isValidFragment() from PreferenceActivity gets called?
http://securityintelligence.com/new-vulnerability-android-framework-fragment-injection#.VRGSv1V_NBc