使用 TabActivity 中的 ListActivity 启动 ListActivity?
我有一个由 TabActivity 扩展的类,它创建多个选项卡。 一个选项卡由 ListActivity 扩展,当您在列表中选择一个选项时,应该打开一个新活动。问题是此代码将丢失选项卡(在属于 TabActivity 成员的 ListActivity 中打开一个新活动):
Intent myIntent = new Intent(view.getContext(), MyOtherActivity.class);
startActivity(myIntent);
有解决方案吗? 感谢您的回答!
I have a class extended by TabActivity that creates multiple tabs.
One tab is extended by ListActivity and should open a new activity when you choose an option in the list. The problem is that this code will lose the tabs (opening a new activity in the ListActivity that is member of the TabActivity):
Intent myIntent = new Intent(view.getContext(), MyOtherActivity.class);
startActivity(myIntent);
Is there a solution to this?
Thanks for answering!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以自由地更改您的设计,那么这将是一个更简单的解决方案,并且您将拥有一个具有以
ViewFlipper
为根的自定义布局的活动,而不是ListActivity
代码>.在此ViewFlipper
中,您可以将第一个“页面”设置为您的ListView
,将第二个页面设置为子活动的视图。单击项目时,您只需在视图翻转器上调用
showNext
,并根据所选项目使用正确的数据填充第二个布局。It would be an easier solution, if you would have the liberty to change a bit your design, and instead of the
ListActivity
you would have an activity with a custom layout rooted by aViewFlipper
. Inside thisViewFlipper
you could set the first 'page' to yourListView
, and the second page to the child activity's view.On item click you just call
showNext
on the viewflipper, and populate the second layout with the proper data based on the selected item.编辑:根据 MisterSquonk 的评论,我可能误解了这个问题。我不相信您可以轻松更改该特定选项卡中的活动,但您有两个同样可行的选择:
使用
ListView
删除选项卡并使用新添加新选项卡活动
添加一个新选项卡:
public void addTab (TabHost.TabSpec tabSpec)
您可以按照此处的响应删除单个选项卡:如何删除来自 TabHost 的选项卡
改用常规的
Activity
并添加带有ListView
和替代内容的FrameLayout
里面:bringToFront ()
确定View
z 顺序setVisibility()
来设置 VISIBLE 或 GONE旧的,可能不相关的信息:
这里有几个处理类似设置的问题:
<一href="https://stackoverflow.com/questions/5116837/listactivity-inside-tabactivity">TabActivity 内的 ListActivity
从 android 中的 tabactivity 调用 listactiviy
甚至还有错误报告:http://code.google.com/p/android/issues/detail? id=3443
你可以看看他们是如何实现的。我的 0.02 美元,只需扩展
Activity
并在其中添加一个ListView
即可。Edit: As per MisterSquonk comment, I may have misunderstood the issue. I do not believe you can easily change the activity in that particular tab, but you have two equally feasible options:
remove the tab with the
ListView
and add a new tab with the newActivity
Add a new tab with:
public void addTab (TabHost.TabSpec tabSpec)
You can remove a single tab following the response here: How to remove tab from TabHost
Use a regular
Activity
instead and add aFrameLayout
with theListView
and your alternative content inside:bringToFront ()
to determine theView
z ordersetVisibility()
to either VISIBLE or GONEOld, probably irrelevant info:
There are a couple of questions here dealing with similar setups:
ListActivity inside TabActivity
calling listactiviy from tabactivity in android
and even a bug report: http://code.google.com/p/android/issues/detail?id=3443
You can take a look at how they implemented it. My $0.02, just extend
Activity
instead and add aListView
inside.