Adding other components along with iconified text list

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Adding other components along with iconified text list

Postby radhika » Wed May 21, 2008 4:02 pm

Hi PlusMinus,

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ScreenMdplOne extends ListActivity //implements OnItemSelectedListener
  2.  
  3. {
  4.  
  5.     /** Called when the activity is first created. */
  6.  
  7.         //TextView t;
  8.  
  9.         //ListView l;
  10.  
  11.     @Override
  12.  
  13.     public void onCreate(Bundle icicle) {
  14.  
  15.         super.onCreate(icicle);
  16.  
  17.         TextView text_view;
  18.  
  19.         Button button;
  20.  
  21.         text_view=new TextView(this);
  22.  
  23.         text_view.setText("content overview area");
  24.  
  25.  
  26.  
  27.         button=new Button(this);
  28.  
  29.         button.setText("Select");
  30.  
  31.  
  32.  
  33.         IconTextAdapter ita=new IconTextAdapter(this);
  34.  
  35.         IconText it1 = new IconText("Audio",getResources().getDrawable(R.drawable.favicon));
  36.  
  37.         IconText it2 = new IconText("Video",getResources().getDrawable(R.drawable.bug));
  38.  
  39.         IconText it3 = new IconText("Streaming",getResources().getDrawable(R.drawable.locale));
  40.  
  41.        
  42.  
  43.         ita.addItem(it1);
  44.  
  45.         ita.addItem(it2);
  46.  
  47.         ita.addItem(it3);
  48.  
  49.         setListAdapter(ita);
  50.  
  51.         this.setContentView(text_view);
  52.  
  53.      
  54.  
  55.        
  56.  
  57.     }
  58.  
  59. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


If i do this am getting a runtime error.
Cant we have many other components along with a list.
Please help!!!!
Thank you
Regards
radhika
Desire to learn
radhika
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed May 14, 2008 8:09 am
Location: India

Top

Postby Jesmiatka » Thu May 22, 2008 1:40 pm

You can, but you are approaching it the wrong way!
You are now setting a textview as the only content in a ListActivity. Which is impossible since a listactivity requires a ListView with a special id.
If you want to use an activity extending ListActivity then at least add a ListView with the id "@android:id/list"

The easiest way doing this (in my opinion) is by creating your layout in XML and it must have at least the following attribute:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  <ListView android:id="@android:id/list"
  2.  
  3.    android:layout_width="fill_parent"
  4.  
  5.    android:layout_height="wrap_content"
  6.  
  7.    />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


You can also create your textviews in here and read/edit them in Java by finding them with findViewById.

Hope this helps!

Yours sincerely,
Mike
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 9 guests