Fancier List View inside a tab

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

Fancier List View inside a tab

Postby gstavrev » Wed Jul 29, 2009 9:51 pm

Hi there,

I have been trying to build a list view inside a tab. i have the basic one working with the tabs and the list view, but now I want to have a list view that also shows images, not just text. This is where I have a problem. I am looking at this tutorial

http://androidguys.com/?p=633

but its not very helpful, since i can't extend listActivity.

Can you please suggest what I can do or look at? This is part of my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class tl extends TabActivity {
  3.  
  4.        
  5.  
  6.         ListView l1, l2;
  7.  
  8.        
  9.  
  10.     /** Called when the activity is first created. */
  11.  
  12.     @Override
  13.  
  14.     public void onCreate(Bundle savedInstanceState) {
  15.  
  16.         super.onCreate(savedInstanceState);
  17.  
  18.        
  19.  
  20.         TabHost mTabHost = getTabHost();
  21.  
  22.        
  23.  
  24.         l1 = new ListView(toolmaster.this);  
  25.  
  26.         l2 = new ListView(toolmaster.this);
  27.  
  28.  
  29.  
  30.         TabSpec t1 = mTabHost.newTabSpec("tab_2");
  31.  
  32.         TabSpec t2 = mTabHost.newTabSpec("tab_1");
  33.  
  34.        
  35.  
  36.         t1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.t1));
  37.  
  38.         t2.setIndicator("Tab 2",getResources().getDrawable(R.drawable.t2));
  39.  
  40.        
  41.  
  42.         t1.setContent(new TabHost.TabContentFactory(){
  43.  
  44.             public View createTabContent(String tag)
  45.  
  46.             {                                            
  47.  
  48.  
  49.  
  50.                  ArrayAdapter<String> adapter = new ArrayAdapter<String>(tl.this,android.R.layout.simple_list_item_1,new String[]{"item1", "item2", "item3", "item4", "a", "b"});
  51.  
  52.  
  53.  
  54.         //    ArrayAdapter<String> adapter = new ArrayAdapter<String>(tl.this,R.layout.formulalist, R.id.label, new String[]{"item1", "item2", "item3", "item4", "a", "b"});
  55.  
  56.                  
  57.  
  58.                  l1.setAdapter(adapter);  
  59.  
  60.                  return l1;
  61.  
  62.             }          
  63.  
  64.        });
  65.  
  66.        
  67.  
  68.         t2.setContent(new TabHost.TabContentFactory(){
  69.  
  70.             public View createTabContent(String tag)
  71.  
  72.             {                                            
  73.  
  74.                  ArrayAdapter<String> adapter = new ArrayAdapter<String>(tl.this,android.R.layout.simple_list_item_1,new String[]{"item1", "item2", "item3", "item4", "a", "b"});
  75.  
  76.                  l2.setAdapter(adapter);  
  77.  
  78.                  return l2;
  79.  
  80.             }          
  81.  
  82.        });
  83.  
  84.        
  85.  
  86.         mTabHost.addTab(t1);
  87.  
  88.         mTabHost.addTab(t2);
  89.  
  90.  
  91.  
  92.         mTabHost.setCurrentTab(0);
  93.  
  94.     }
  95.  
  96. }
  97.  
  98.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


I have attempted to switch the commented and uncommented array adapter in the first tab, along with this "formulalist.xml"

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <linearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  4.  
  5.    android:layout_width="fill_parent"  
  6.  
  7.    android:layout_height="wrap_content"  
  8.  
  9.    android:orientation="horizontal"  
  10.  
  11. >  
  12.  
  13.     <imageView  
  14.  
  15.        android:id="@+id/icon"  
  16.  
  17.        android:layout_width="32px"  
  18.  
  19.        android:paddingLeft="2px"  
  20.  
  21.        android:paddingRight="2px"  
  22.  
  23.        android:paddingTop="2px"  
  24.  
  25.        android:layout_height="wrap_content"  
  26.  
  27.        android:src="@drawable/sci_tab"  
  28.  
  29.    />  
  30.  
  31.     <textView  
  32.  
  33.        android:id="@+id/label"  
  34.  
  35.        android:layout_width="wrap_content"  
  36.  
  37.        android:layout_height="wrap_content"  
  38.  
  39.        android:textSize="44sp"  
  40.  
  41.    />  
  42.  
  43. </linearLayout>  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


But with no success. I get an error and my app crashes.

Thanks for the help. I am still kind of new at this.
gstavrev
Freshman
Freshman
 
Posts: 5
Joined: Wed Dec 24, 2008 7:35 am
Location: Los Angeles, CA

Top

Postby gstavrev » Thu Jul 30, 2009 4:56 am

I got it taken care of. It is very similar to the Contacts app, so I just looked at the source of it.
gstavrev
Freshman
Freshman
 
Posts: 5
Joined: Wed Dec 24, 2008 7:35 am
Location: Los Angeles, CA

how

Postby Dayn » Wed Aug 05, 2009 9:12 am

Hi

how to fix it ?

Dayn
User avatar
Dayn
Developer
Developer
 
Posts: 31
Joined: Thu Jul 09, 2009 10:45 am
Location: Paris and Dijon

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests