Android 在 PreferenceScreen 之间切换
我有一个 PreferencesScreen,其中有一些首选项和一个子屏幕。它看起来像这样:
<PreferenceScreen android:key="root">
<Preference android:key="first" />
<PreferenceScreen android:key="subScreen" />
<Preference android:key="second" />
<Preference android:key="third" />
</PreferenceScreen>
</PreferenceScreen>
当用户单击子屏幕时,他会移动到子屏幕视图。现在,当用户单击“第二个”或“第三个”时,我想将用户重定向到“root”首选项屏幕。我似乎没有找到正确的 API 来关闭子屏幕或聚焦前一个屏幕。有想法吗?
I have a PreferencesScreen, that has some Preferences and a sub-screen. It looks like this:
<PreferenceScreen android:key="root">
<Preference android:key="first" />
<PreferenceScreen android:key="subScreen" />
<Preference android:key="second" />
<Preference android:key="third" />
</PreferenceScreen>
</PreferenceScreen>
When user clicks the subscreen, he is moved to the subscreen view. Now I want to redirect the user to "root" preference screen when he clicks on "second" or "third". I don't seem to find the right API to either close the subscreen, or focus the previous one. Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首选项子屏幕显示为对话框,在您的情况下,关闭代表相应
PreferenceScreen
的对话框就足够了。将以下代码片段插入到您可能为“第二”和“第三”首选项设置的OnPreferenceClickListener
的onPreferenceClick()
方法中以关闭对话框:其中
PrefsActivity
是应用程序中使用的PreferenceActivity
的封闭实例。Preference subscreen is displayed as a dialog, in your case it would be enough to dismiss the dialog representing appropriate
PreferenceScreen
. Insert the following snippet intoonPreferenceClick()
method ofOnPreferenceClickListener
you probably set for "second" and "third" preferences to close the dialog:where
PrefsActivity
is the enclosing instance ofPreferenceActivity
that is used in your application.我不知道为什么你首先只有
Preference
元素。在我的脑海中,我无法想象用户会在“设置”中遇到您想要的行为的任何地方,因此您尝试做的事情可能是意想不到的。另外,我建议您开始放弃嵌套的PreferenceScreen
元素,因为 Honeycomb 的新方向是PreferenceFragments
。话虽如此,请在
PreferenceActivity
上尝试setPreferenceScreen()
并查看它是否满足您的需要。I have no idea why you have bare
Preference
elements in the first place. Off the top of my head, I cannot think of anywhere in Settings where the user would encounter your desired behavior, so what you are trying to do is likely to be unexpected. Also, I recommend you start to move away from nestedPreferenceScreen
elements, as the new direction isPreferenceFragments
for Honeycomb onward.That being said, try
setPreferenceScreen()
onPreferenceActivity
and see if it gives you what you need.