Basic List

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

Basic List

Postby williamzanelli » Thu Apr 02, 2009 12:24 am

Hi guys,

Can some please post code for a basic list

I'm reading the tutorials(http://developer.android.com/guide/tuto ... d-ex2.html) and getting confused with the database code etc..

I have an array with data like {"one", "two", "three", "four". "five"}, and using the ListView, I want to be able to liste the items,

Can someone please post the Java amd the XML code..

Thanks

Will
Will
williamzanelli
Experienced Developer
Experienced Developer
 
Posts: 63
Joined: Mon Jan 05, 2009 2:37 am
Location: UK

Top

Postby Alexandro » Thu Apr 02, 2009 8:28 am

Your main layout:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <AbsoluteLayout
  5.  
  6.         android:id="@+id/listLayout"
  7.  
  8.         android:layout_width="fill_parent"
  9.  
  10.         android:layout_height="fill_parent"
  11.  
  12.         xmlns:android="http://schemas.android.com/apk/res/android"
  13.  
  14.         >
  15.  
  16.         <ListView
  17.  
  18.                 android:id="@+id/listView"
  19.  
  20.                 android:layout_width="fill_parent"
  21.  
  22.                 android:layout_height="fill_parent"
  23.  
  24.                 >
  25.  
  26.         </ListView>
  27.  
  28. </AbsoluteLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Your row.xml (the xml that describes how rows in your list will look like. Put in layouts dir.) :
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <TextView
  5.  
  6.         android:id="@+id/rowText"
  7.  
  8.         android:layout_width="fill_parent"
  9.  
  10.         android:layout_height="fill_parent"
  11.  
  12.         >
  13.  
  14. </TextView>
  15.  
  16.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


In code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ListView list = (ListView) findViewById(R.id.listView);
  3.  
  4. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.row,yourArray);
  5.  
  6. list.setAdapter(adapter);
  7.  
  8.  
Parsed in 0.041 seconds, using GeSHi 1.0.8.4
Alexandro
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 05, 2009 5:42 pm

Postby williamzanelli » Thu Apr 02, 2009 2:16 pm

Thanks for the reply Alex!! :D :D :D
Will
williamzanelli
Experienced Developer
Experienced Developer
 
Posts: 63
Joined: Mon Jan 05, 2009 2:37 am
Location: UK

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests