2014-08-23 3 views
0

Я пытаюсь отобразить пару ключевых значений, используя ListView, но не отображает данные, даже если adapter не является null.ListView не отображает данные, даже если адаптер не пуст

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> 

ответ

1

Измените код на следующих строках:

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}); 
+0

'shop' и' 'subject' являются переменными типа String', который содержит данные. –

+0

Я отредактировал ответ, теперь, возможно, его более ясный – Maddy

+0

ohh да да ... получил это ... спасибо :) –

Смежные вопросы