Start ListActivity using ListActivity from a TabActivity?
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.ge开发者_开发技巧tContext(), MyOtherActivity.class);
startActivity(myIntent);
Is there a solution to this? Thanks for answering!
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 a ViewFlipper
. Inside this ViewFlipper
you could set the first 'page' to your ListView
, 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.
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:- use
bringToFront ()
to determine theView
z order - use
setVisibility()
to either VISIBLE or GONE
- use
Old, 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 a ListView
inside.
精彩评论