Carl wrote:
> I am trying to build a listactivity with listitems that consist of two
> textviews. Unfortunately I don't see anything but lines in my list.
> Can anyone tell me whats wrong with this code?
> 
> 
> in list_item.xml
> 
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout
>      xmlns:android="http://schemas.android.com/apk/res/android";
>      android:layout_width="fill_parent"
>      android:layout_height="wrap_content"
>      android:orientation="vertical">
> 
>      <TextView android:id="@+id/text1"
>          android:textSize="16px"
>          android:textStyle="bold"
>          android:layout_width="fill_parent"
>          android:layout_height="wrap_content"/>
> 
>      <TextView android:id="@+id/text2"
>          android:textSize="12px"
>          android:textStyle="italic"
>          android:layout_width="fill_parent"
>          android:layout_height="wrap_content"/>
> </LinearLayout>
> 
> in my class:
> 
> public class mylv extends ListActivity
> {
>       ArrayList<HashMap<String,String>> list = new
> ArrayList<HashMap<String,String>>();
> 
>       /** Called when the activity is first created. */
>       @Override
>       public void onCreate(Bundle savedInstanceState)
>       {
>               super.onCreate(savedInstanceState);
> 
>               // add items to the list
>                                 HashMap<String,String> item1 = new
> HashMap<String,String>();
>               item1.put("line1", "one");
>               item1.put("line2", "two");
>               list.add(item1);
>               HashMap<String,String> item2 = new HashMap<String,String>();
>               item2.put("line3", "three");
>               item2.put("line4", "four");
>               list.add(item2);
>               HashMap<String,String> item3 = new HashMap<String,String>();
>               item3.put("line5", "five");
>               item3.put("line6", "six");
>               list.add(item3);
> 
>               // build the list adapter
>               ListAdapter adapter = new SimpleAdapter(
>                       this,
>                       list,
>                       R.layout.list_item,
>                       new String[] { "label", "description" },
>                       new int[] { R.id.text1, R.id.text2 }
>               );
> 
>               // show the items
>               setListAdapter(adapter);
>       }
> }

Your HashMaps do not have anything named "label" or "description".
Change your HashMap keys to "label" and "description".

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books.html

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to