从嵌套的 Android PreferenceScreen 返回到上一个 PreferenceScreen
我正在以编程方式创建一组嵌套的 PreferenceScreen
。当用户潜入其中一个屏幕并点击其中的某些内容时,我想返回到上一个 PreferenceScreen
(即“父级”)。
我找不到任何相关信息,并且调用 finish()
并不能完成这项工作,而是从所有 PreferenceScreen
返回,而不是仅返回一个。
I am programmatically creating a nested set of PreferenceScreen
s. When the user dives into one of these screens, and taps something in there, I want to go back to the previous PreferenceScreen
, (i.e. the "parent").
I couldn't find any information on this, and calling finish()
doesn't do the job but rather returns from ALL the PreferenceScreen
s instead of just one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚遇到问题并找到了解决方案。
您可以重写 PreferenceActivity 中的 onPreferenceTreeClick 方法。
调用参数preferenceScreen的getDialog方法,然后调用对话框的dismiss方法。
就这样,快乐!
I just meet the problem and just found the solution.
You can override the method onPreferenceTreeClick in PreferenceActivity.
call the param preferenceScreen's getDialog method, then call the dialog's dismiss method.
just like this, joy!
您可以将第一个打开,而不是在启动第二个的那个上调用 finish() 。如果这不起作用,您可以保存第一个屏幕的状态,而不是“返回”,而是通过 Intent 调用它并让它加载之前的状态。
You can either leave the first one open buy not calling finish() on the one that launched the second one. If this does not do it, you could save the state of the first screen and instead of 'going back' you call it by an Intent and have it load its previous state.
尝试类似的操作:
使用自定义首选项类别,例如:
Try something like:
With a custom preference category like: