简体   繁体   中英

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.getContext(), MyOtherActivity.class);
startActivity(myIntent);

Is there a solution to this? Thanks for answering!

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:

  • 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM