开发者

Start ListActivity using ListActivity from a TabActivity?

开发者 https://www.devze.com 2023-03-03 12:31 出处:网络
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 co

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 new Activity
    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 a FrameLayout with the ListView and your alternative content inside:

    • use bringToFront () to determine the View z order
    • use setVisibility() to either VISIBLE or GONE

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消