How to map objects to lists

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

How to map objects to lists

Postby ralphz » Thu Feb 18, 2010 7:07 am

Hello all. Great forum!

I started learning Java and Android development two weeks ago so please be patient with me :)

My problem.

i have a simple activity:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class peopleList extends ListActivity
  3.  
  4. {
  5.  
  6.         @Override
  7.  
  8.         public void onCreate(Bundle savedInstance)
  9.  
  10.         {
  11.  
  12.                 Log.d(LIST_LOG_TAG, "onCreate() invoked!");
  13.  
  14.                 super.onCreate(savedInstance);
  15.  
  16.                 setContentView(R.layout.found_people_list);
  17.  
  18.                
  19.  
  20.                 ArrayList<RemPerson> foundDevices = MyOtherService.foundDevices;
  21.  
  22.                
  23.  
  24.                 ListAdapter adapter = new SimpleAdapter
  25.  
  26.                 (
  27.  
  28.                    //This is where i have a problem
  29.  
  30.                 );
  31.  
  32.                
  33.  
  34.                
  35.  
  36.         }
  37.  
  38. }
  39.  
  40.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


My goal is to display a list of RemPerson objects. The class itself looks like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. class RemPerson
  3.  
  4.         {
  5.  
  6.                 public String devName;
  7.  
  8.                 public String devAddress;
  9.  
  10.  
  11.  
  12.                 public RemPerson(String devName, String devAddress)
  13.  
  14.                 {
  15.  
  16.                         this.devAddress = devAddress;
  17.  
  18.                         this.devName = devName;
  19.  
  20.                 }
  21.  
  22.         }
  23.  
  24.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


found_people_list.xml layout:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout
  5.  
  6.  xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.  android:layout_width="wrap_content"
  9.  
  10.  android:layout_height="wrap_content">
  11.  
  12.  
  13.  
  14.   <TextView
  15.  
  16.         android:id="@id/android:list"
  17.  
  18.         android:layout_width="wrap_content"
  19.  
  20.         android:layout_height="wrap_content"
  21.  
  22.         />
  23.  
  24.  
  25.  
  26.   <TextView
  27.  
  28.         android:id="@+id/deviceAddress"
  29.  
  30.         android:layout_width="wrap_content"
  31.  
  32.         android:layout_height="wrap_content"
  33.  
  34.         />
  35.  
  36.  
  37.  
  38. </LinearLayout>
  39.  
  40.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


my peoplelist.xml layout:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.  
  4.     android:layout_width="fill_parent"
  5.  
  6.     android:layout_height="wrap_content"
  7.  
  8.     android:orientation="vertical">
  9.  
  10.  
  11.  
  12.      <TextView android:id="@+id/text1"
  13.  
  14.         android:textSize="16sp"
  15.  
  16.         android:textStyle="bold"
  17.  
  18.         android:layout_width="fill_parent"
  19.  
  20.         android:layout_height="wrap_content"/>
  21.  
  22.  
  23.  
  24.      <TextView android:id="@+id/text2"
  25.  
  26.         android:textSize="16sp"
  27.  
  28.         android:layout_width="fill_parent"
  29.  
  30.         android:layout_height="wrap_content"/>
  31.  
  32.  </LinearLayout>
  33.  
  34.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


My question is how do i map devAddress and devName properties of the RemPeople object to list elements.

I hope my question is clear enough. Thanks for any help
ralphz
Freshman
Freshman
 
Posts: 5
Joined: Sat Jan 16, 2010 11:18 pm

Top

Postby amplifier78 » Thu Feb 18, 2010 3:08 pm

I'm working with the same. Here's a link with an example

http://ykyuen.wordpress.com/2010/01/03/ ... leadapter/

anyway I only get a blank screen :roll:
amplifier78
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Feb 15, 2010 2:02 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 5 guests