ListView in a TabHost

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

ListView in a TabHost

Postby ThomasB » Fri Feb 20, 2009 5:43 pm

Hi there,

I got stuck on the following issue:

I have a TabHost with several tabs with a ListView. No i want to start a new Activity inside the current tab when a list item is clicked. If a start a new activity onListItemClick it opens the activity fullscreen.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyTabActivity extends TabActivity {
  2.  
  3.        
  4.  
  5.         @Override
  6.  
  7.         protected void onCreate(Bundle savedInstanceState) {
  8.  
  9.                 super.onCreate(savedInstanceState);
  10.  
  11.                
  12.  
  13.                 setContentView(R.layout.mytabactivity);        
  14.  
  15.  
  16.  
  17.         final TabHost tabHost = getTabHost();
  18.  
  19.  
  20.  
  21.         TabSpec ts1 = tabHost.newTabSpec("Tab1");
  22.  
  23.         ts1.setIndicator("Tab1", null);
  24.  
  25.         ts1.setContent(new Intent(this, TabView1.class));
  26.  
  27.         tabHost.addTab(ts1);
  28.  
  29.  
  30.  
  31.         TabSpec ts2 = tabHost.newTabSpec("Tab2");
  32.  
  33.         ts2.setIndicator("Tab2", null);
  34.  
  35.         ts2.setContent(new Intent(this, TabView2.class));
  36.  
  37.         tabHost.addTab(ts2);
  38.  
  39.        
  40.  
  41.         }
  42.  
  43. }
  44.  
  45.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class TabView1 extends ListActivity {
  3.  
  4.  
  5.  
  6.         @Override
  7.  
  8.         public void onCreate(Bundle savedInstanceState) {
  9.  
  10.                 super.onCreate(savedInstanceState);
  11.  
  12.  
  13.  
  14.                 setContentView(R.layout.tabview1);
  15.  
  16.                
  17.  
  18.  
  19.  
  20.                 SeparatedListAdapter adapter = new SeparatedListAdapter(this);
  21.  
  22.  
  23.  
  24.  
  25.  
  26.                 //fill list adapter stuff
  27.  
  28.  
  29.  
  30.                 setListAdapter(adapter);
  31.  
  32.         }
  33.  
  34.        
  35.  
  36.         @Override
  37.  
  38.         protected void onListItemClick(ListView l, View v, int position, long id) {
  39.  
  40.                 // TODO Auto-generated method stub
  41.  
  42.                 super.onListItemClick(l, v, position, id);             
  43.  
  44.                        
  45.  
  46.                 Intent i = new Intent(l.getContext(), Movies.class);
  47.  
  48.                 startActivity(i);      
  49.  
  50.         }
  51.  
  52.  
  53.  
  54. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Is my idea possible? Open a new intent in the current tab on a list item click?
ThomasB
Freshman
Freshman
 
Posts: 2
Joined: Fri Feb 20, 2009 5:23 pm
Location: Groningen, Netherlands

Top

Postby dragoff » Fri Feb 20, 2009 7:07 pm

I think that if you want to open new activity inside current, you must to create new TabHost in this tab. Otherwise, its always will be opened as a new Activity, shifting previous to the stack (if I make no mistakes).

The TabHost has many bugs, in particular, when activity in tab content contains only one Spinner or TabHost in TabHost. So, if you try to make new TabHost as a content for current tab, welcome on a board!
dragoff
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Feb 04, 2009 2:34 pm
Location: Odessa, Ukraine

Postby kali » Mon Feb 23, 2009 7:47 am

hai thomas,
Thomas to start new activity you can use Intent()
this will help you to switch from one sceen to another
kali
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 27, 2009 1:31 pm

Postby ThomasB » Tue Feb 24, 2009 5:01 pm

Thanks for the information so far.

At this point I do not have time to get into it (deadlines). So I do open my view as a total new activity. For a later release i'll have a better look for this problem and will post my solution by then.
ThomasB
Freshman
Freshman
 
Posts: 2
Joined: Fri Feb 20, 2009 5:23 pm
Location: Groningen, Netherlands

Postby kali » Wed Feb 25, 2009 2:13 pm

hai you can write any time any post
8)
kali
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 27, 2009 1:31 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests