我正在尝试实现自定义DialogPreference,其布局将使用片段。应用程序应支持API 10(本身不支持片段)。

为了处理片段,我需要获取android.support.v4.FragmentManager的实例(通常通常使用getSupportFragmentManager从支持FragmentActivity接收)。

我不知道如何在DialogPreference中获取android.support.v4.FragmentManager。任何线索表示赞赏。

最佳答案

如果从android.support.v4.app.FragmentActivity调用对话框,则应该能够在DialogPreference类中进行类型转换,以获取Support-FragmentManager:

(android.support.v4.app.FragmentActivity)getContext()).getSupportFragmentManager()


...如果不可能的话,另一个解决方案是launch an activity that looks like a dialog,然后在其中使用您的片段。 How to open an activity from a PreferenceScreen?

07-24 09:49
查看更多