处理单击PreferenceFragment?

时间:2013-06-13 20:42:18

标签: android android-activity android-preferences android-fragmentactivity

你如何处理点击某些偏好?这就是我的代码:

public class SettingsActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        SettingsFragment settingsFragment = new SettingsFragment();
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(android.R.id.content, settingsFragment);
        fragmentTransaction.commit();
    }
}


public class SettingsFragment extends PreferenceFragment
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.menu_settings);
    }
}

1 个答案:

答案 0 :(得分:2)

您可以覆盖方法onPreferenceTreeClick()来处理首选项点击事件

参数Preference是单击的首选项对象。