如何在层次结构中向下启动首选项活动
我正在 API 级别 9 上工作,因此无法使用新的首选项片段。
我有一个首选项活动,根据 api 演示从 xml 文件获取首选项。我有一个偏好屏幕层次结构,因此通常要获得偏好,您必须单击顶级屏幕。
除了从主菜单中获取所有首选项之外,我希望能够在其中一个子屏幕而不是顶部屏幕上启动首选项活动,这样我只需单击一下即可直接在其中一个子屏幕中启动它在与该组子偏好相关的活动中。
有人知道这是否可行吗?我认为有目的地传递一些数据是一种方法,但我找不到任何说明这是可能的。
I am working at API level 9 so can not use the new Preference Fragment stuff.
I have a preference activity getting the preferences from and xml file as per the api demos. I have a hierarchy of preference screens so normaly to get to a preference you have to click though a top level screen.
As well as getting to all the preferences from my main menu I would like to be able to start the preference activity at one of the sub screens rather than the top screen so I can start it directly in one of the sub screens on say a click in an activity that that group of sub preferences is relervant to.
Anyone know if this is posible? I would of thought that passing some data with the intent would be the way but I can not find anything saying this is possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您可以通过 android 兼容性包使用 Preference Fragment: http:// developer.android.com/sdk/compatibility-library.html
其次,是的,这是可能的。当您创建片段或活动(无论您决定)时,请使用 addPreferencesFromIntent() 方法( http://developer.android.com/reference/android/preference/PreferenceFragment.html#addPreferencesFromIntent%28android.content.Intent%29 ),而不是添加整个屏幕,只需添加您想要的子屏幕。
First of all, the Preference Fragment is available to you through the android compatibility package: http://developer.android.com/sdk/compatibility-library.html
Second, yes this is possible. When you're creating your fragment or acitvity (which ever you decide), use the addPreferencesFromIntent() method ( http://developer.android.com/reference/android/preference/PreferenceFragment.html#addPreferencesFromIntent%28android.content.Intent%29 ), and instead of adding the whole screen just add the subscreen you want.
好的,这就是我在柯蒂斯的帮助下得到的结果。
基本上,在我启动首选项活动的代码中,我对所有首选项没有任何操作,如果您只需要其中一些首选项,则需要执行操作。该操作需要与某种首选项或首选项组上的键匹配。
在我的 PreferencesFromXml 类中,我总是添加 xml 中的首选项,但如果我有一个操作,我会搜索首选项以查找匹配的键。如果我找到一个,我会删除所有首选项,然后添加匹配的首选项或其子项(如果它是 PreferenceGroupe)。
OK here is what I have ended up with with Kurtis's help.
Basically in my code starting the Preferences activity I have no action for all the preferences and an action if you want just some of them. The action needs to match the key on a preference or preferenceGroupe of some sort.
In my PreferencesFromXml class I always add the preferences from the xml but then if I have an action I search though the preferences looking for a matching key. If I find one I removeAll preferences then add the matching one or it's children if it is a PreferenceGroupe back in.