Question

When I run the program the TextView texts in each row are being changed from the default text to nothing. The data in the HashMaps are not displaying.

My main application layout(main.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
     android:layout_height="fill_parent">

    <ListView  
        android:id="@android:id/list"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/>

     <TextView android:id="@android:id/empty"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Empty"/>
</LinearLayout>

My list item layout(myrow.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:id="@+id/item1"
        android:text="row_id"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"/>

    <TextView android:id="@+id/item2"
        android:text="row_id"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"/>
</LinearLayout>

My application code(Test.java):

public class Test extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //main list
        ArrayList<HashMap<String, String>> list = 
            new ArrayList<HashMap<String, String>>();

        //data stored in maps and maps added to list
        HashMap<String, String> temp = new HashMap<String, String>();
        temp.put("Name", "test");
        list.add(temp);

        HashMap<String, String> temp2 = new HashMap<String, String>();
        temp2.put("Name1", "test1");
        list.add(temp2);

        String[] names = {"item1", "item2"};
        int[] locations = {R.id.item1, R.id.item2};

        SimpleAdapter adapter = new SimpleAdapter
            (this, list, R.layout.myrow, names, locations);
        setListAdapter(adapter);
    }
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top