Android:TabActivity 在填充内容视图之前执行检查
我有一个 TabActivity 类,它使用意图来填充内容视图。在某些情况下,我想拦截选项卡选择事件,弹出消息对话框,抑制所选的意图,并恢复到所选的原始选项卡。
我希望 TabActivity 内容保持意图驱动(而不是使用视图)。
我怀疑这可能需要扩展 LocalActivityManager。
有没有人曾经完成过这个或做过类似的事情?
// simple example of current code:
TabHost tabHost = getTabHost();
TabSpec ts = tabHost.newTabSpec(tag);
ts.setIndicator(tabview);
ts.setContent(new Intent().setClass(this, AHome.class));
tabHost.addTab(ts);
谢谢!
I have a TabActivity class which uses Intents to populate the content view. Under certain conditions, I would like to intercept a tab selection event, put up a message dialog, suppress the selected Intent, and revert to the original tab selected.
I want the TabActivity content to remain Intent driven (rather than using Views).
I suspect this may require extension of the LocalActivityManager.
Has anyone ever accomplished this or done a similiar thing?
// simple example of current code:
TabHost tabHost = getTabHost();
TabSpec ts = tabHost.newTabSpec(tag);
ts.setIndicator(tabview);
ts.setContent(new Intent().setClass(this, AHome.class));
tabHost.addTab(ts);
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不会在 TabActivity 中寻找答案(甚至 Google 员工也承认这个 API 已损坏)。
这就是我所做的 - 在目标活动中,我会在 onCreate 中检查此条件,如果满足条件,则继续,如果不满足 - 激活前一个活动
I wouldn't look in the TabActivity for the answer (even Google staff admit that this API is broken).
Here's what I do - in the target activity, I'd check this condition in the onCreate, if the condition is satisfied, continue, if no - activate the previous activity
在深入研究 Android 的 TabHost src 之后,这里有一个相当简单的问题解决方案。它允许以图形方式“触摸”选项卡按钮,但仍保持未选中状态,并阻止对所选选项卡进行任何处理(假设所有 OnTabSelected 侦听器都已知晓)。
只需扩展 TabHost 类:
然后在用于 TabActivity 的 XML 中将引用从 TabHost 更改为 MyTabHost:
另一件要记住的事情是,如果您使用 TabActivity.getTabHost ()在TabActivity中,它会返回一个MyTabHost。例如:
After a little digging into Android's TabHost src, here's a fairly simple solution to the problem. It allows the tab button to be "touched" graphically yet still remain unselected and it prevents any processing of the selected tab (assuming that all the OnTabSelected listeners have been made aware).
Just Extend the TabHost class:
And then change your reference from TabHost to MyTabHost in the XML used for the TabActivity:
One other thing to remember is that if you use TabActivity.getTabHost() in the TabActivity, it will return a MyTabHost. e.g.: