Amit Anand
Amit Anand

Reputation: 1225

ListView not displaying data even if adapter is not empty

I am trying to display some key-value pair using ListView but it is no displaying the data even if the adapter is not null.

Checkout.java:-

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkout);

ListView list = (ListView) findViewById(R.id.listView1);

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("shopK", "SHOP NAME");
map.put("shopV", shop);
mylist.add(map);
map = new HashMap<String, String>();
map.put("subjectK", "SUBJECT");
map.put("subjectV", subject);
mylist.add(map);
for(int i=0;i<products.size();i++){
    map = new HashMap<String, String>();
    map.put("productK", "PRODUCT NAME");
    map.put("productV", products.get(i));
    mylist.add(map);    
}
SimpleAdapter checklist = new SimpleAdapter(this, mylist, R.layout.row,
            new String[] {"TITLE", "VALUE"}, new int[] {R.id.TITLE_CELL, R.id.VALUE_CELL});
list.setAdapter(checklist);
}

checkout.xml:-

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

  <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1" >

    </ListView>

</RelativeLayout>

row.xml:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="4dip"
     android:paddingBottom="6dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal">

     <TextView android:id="@+id/TITLE_CELL"
         android:layout_width="50dip"
         android:layout_height="wrap_content"/>

     <TextView android:id="@+id/VALUE_CELL"
         android:layout_width="70dip"
         android:layout_height="wrap_content" android:layout_weight="1"/>
</LinearLayout>

Upvotes: 0

Views: 101

Answers (1)

mesh
mesh

Reputation: 937

Change your code on below lines:

HashMap<String, String> map = new HashMap<String, String>();
map.put("TITLE", "ShopK");
map.put("VALUE", "SubjectK");
mylist.add(map);
map = new HashMap<String, String>();
map.put("TITLE", "ShopV");
map.put("VALUE", "SubjectV");
mylist.add(map);

SimpleAdapter checklist = new SimpleAdapter(this, mylist, R.layout.row,
            new String[] {"TITLE", "VALUE"}, new int[] {R.id.TITLE_CELL, R.id.VALUE_CELL});

Upvotes: 1

Related Questions