0

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!

Caspar Kleijne
  • 21,552
  • 13
  • 72
  • 102
dataviruset
  • 109
  • 1
  • 9

2 Answers2

0

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.

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • 2
    I may be wrong but as far as I can tell, the OP wants to simply 'switch' the tab content (in one particular tab) from one Activity to another Activity rather than launch a new Activity which 'covers' the TabActivity. It's not specifically a ListActivity issue it's a general Activity as a tab content -> switch to any other Activity as a tab content issue. – Squonk May 08 '11 at 06:12
  • @MisterSquonk you're probably right. Added two options to address that issue. – Aleadam May 08 '11 at 19:43
  • Sorry, but I don't quite see where I am supposed to put the code for adding a new tab and deleting the old one? Thanks for answering! – dataviruset May 09 '11 at 12:53
  • It would be good if I could access the TabHost from my ListActivity classes, is there a possibility? I have to reach the TabHost in my TabActivity class, right? – dataviruset May 09 '11 at 13:04
  • @dataviruset simply use `getParent()` from your `ListActivity`. See http://developer.android.com/reference/android/app/Activity.html#getParent%28%29 and http://stackoverflow.com/questions/2945274/android-tabhost-update-tabs-from-tabs-activity/2945675#2945675 – Aleadam May 09 '11 at 14:42
0

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.

rekaszeru
  • 19,130
  • 7
  • 59
  • 73