父活动中的 onKeyDown 或 onBackPressed
我有一个 TabActivity 显示其他 Activities 作为基于选择的选项卡的内容。我想要做的是从“父”活动尝试捕获后退键按下,但是 onKeyDown() 也不是 onBackPressed() 在父级中被调用...它由“子”活动处理。有什么方法可以让它传递给“父”活动吗?
I have a TabActivity that shows other Activities as the content based on which tab is selected. What I want to do is from the 'parent' Activity try to capture the back key press, but neither onKeyDown() nor onBackPressed() ever get called in the parent... it's being handled by the 'child' Activities. Is there any way to have it pass up to the 'parent' Activity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不直接在子 Activity 中使用:
Why not just using, from within the child Activity:
您可以在 TabActivity 和他的孩子之间建立一个通信过程。
我在 TabActivity 中创建了一个静态 Handler ,它是在 onCreate 中初始化的选项卡活动。
然后我创建了一个静态 getHandler() 方法(在 TabActivity 中)。
现在,为您的孩子解答您的问题的一个片段是:
You could set up a communication procedure between the TabActivity and his childs.
I created a static Handler in the TabActivity which was initialized in the onCreate of the TabActivity.
Then i created a static getHandler() method (in the TabActivity ).
Now a snippet to achieve your question for your childs would be:
我也遇到了同样的问题。我是这样解决的:
I have encountered the same problem as well. I sovled it this way: