2

我有一个带有导航抽屉菜单的应用程序。当我单击菜单中的某个项目时,我想显示一个设置片段。

当我单击该项目时,它会调用:

Fragment fragment = new SettingsFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

SettingsFragment 被称为:

import java.util.List;

import com.rss.R;
import android.os.Bundle;
import android.preference.PreferenceActivity.Header;
import android.preference.PreferenceFragment;


public class SettingsFragment extends PreferenceFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.preferences);
    }

    public void onBuildHeaders(List<Header> target) {
        loadHeadersFromResource(R.xml.preferences, target);
    }

}

问题是我有这个错误:

The method loadHeadersFromResource(int, List<PreferenceActivity.Header>) is undefined for the type SettingsFragment

看来我不能将 loadHeaderFromResources 与 PreferenceFragment 一起使用,而我必须改为 PreferenceActivity ?

这也是我的 preferences.xml 的代码:

<?xml version="1.0" encoding="utf-8"?>
<preference-headers
        xmlns:android="http://schemas.android.com/apk/res/android">

    <header android:fragment="com.rss.preferences.ExperienceUtilisateur"
            android:icon="@drawable/ic_action_users"
            android:title="User experience"
            android:summary="Manage notifications" >
        <extra android:name="someKey" android:value="someOtherHeaderValue" />
    </header>

    <header android:icon="@drawable/ic_action_star_10"
            android:title="Follow us"
            android:summary="Help us">
        <intent android:action="android.intent.action.VIEW" android:data="http://market.android.com/details?id=com.app.mobideals" />
    </header>

</preference-headers>
4

1 回答 1

0

标头仅用于 PreferenceActivity 而不是 PreferenceFragment

于 2015-04-04T03:12:11.377 回答