我有一个扩展 PreferenceFragment 的类 profileFragment。我有另一个扩展片段的 myFragment 类。如何在 Fragment 类中调用 PreferenceFragment 类?这很重要,因为我使用基于片段的滑动菜单,因此我无法从片段中的其他任何地方调用 PreferenceFragment
问问题
839 次
1 回答
0
I don't have enough information to give you a full answer, as it seems to me if you have a sliding menu based on fragments, you could just add a "Settings" option in your sliding menu, and navigate to it using the FragmentManager from the Activity.
A few things you may want to consider (I'd personally recommend looking at #3):
- As I mentioned above, having a separate "Settings" Navigation item in your sliding menu.
- Making a call from your normal fragment to your Activity to navigate to the PreferenceFragment. You'd want to read up on Fragment Communicationto learn how you should talk to your Activity though.
- You might not even need a PreferenceFragment. It sounds like maybe a better use case for what you are trying to do might be a DialogPreference.
- You could also look into using Child Fragments ( getChildFragmentManager() ), and having your PreferenceFragment be a child fragment of your other fragment. This is getting a bit complicated though.
于 2013-07-20T19:43:08.283 回答