Accessing TabHost from a ListActivity

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Accessing TabHost from a ListActivity

Postby Boni2k » Sun Dec 20, 2009 11:05 pm

Hello,
I try to keep it short.
I have a TabActivity which creates a tab that has a ListActivity set as content (.setContent(new Intent(this, Messagelist.class)). If I click on a ListItem I'd like to create a new tab on the fly. How could I achieve this?

To do this I currently use an example found here: coderanch.com/t/444206/Android/Mobile/Creating-multiple-tabs-one-after . But it seems to be quite hacky. Everytime I click on a ListItem it creates a new TabView which slows everything down.

My current onCreate method in the TabActivity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. super.onCreate(icicle);
  2.  
  3. Bundle extras = getIntent().getExtras();
  4.  
  5. if (extras != null)
  6.  
  7.         count = extras.getInt("Tab");
  8.  
  9. else
  10.  
  11.         count = 0;
  12.  
  13.                                
  14.  
  15. final TabHost myTabHost = getTabHost();
  16.  
  17. myTabHost.setup();
  18.  
  19. messageliste = getIntent().getStringExtra("messagelist");
  20.  
  21. myTabHost.addTab(myTabHost.newTabSpec("tab2").setIndicator("Liste").setContent(new Intent(this, Messagelist.class).putExtra("messagelist", messageliste)));
  22.  
  23.  
  24.  
  25. for (int i = 0; i < count; i++) {
  26.  
  27.         myTabHost.addTab(myTabHost.newTabSpec("tab3")
  28.  
  29.         .setIndicator("Message")
  30.  
  31.         .setContent(new Intent(this, Message.class).putExtra("messagelist", messageliste).putExtra("position",1)));
  32.  
  33.         myTabHost.setCurrentTab(1);
  34.  
  35. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


A new tab is created by ListActivity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. startActivity(new Intent(v.getContext(), start.class).putExtra("Tab", 1).putExtra("messagelist", messageliste).putExtra("position", position));
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Is there a way to access my existing TabHost from my ListActivity without going this detour?
I probably have the same problem like guy: anddev.org/viewtopic.php?p=23160 .

Help is very appreciated :)
Greetings, Boni
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Top

Postby jwei512 » Mon Dec 28, 2009 7:31 am

Have you tried playing with the startActivityForResult and onActivityResult methods?

What you can try doing is override the onActivityResult method in your TabActivity class, and within your TabActivity class start the ListActivity but with result.

Then when you click something in the ListActivity, return the result as "position" in your case (or that's what it looks like from the example you gave) and in your onActivityResult method simply add some code which appends another tab to your TabActivity.

Let me know if this makes sense. I can post some example code if it isn't clear.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 6 guests