2011-08-01 39 views

回答

0

我有這樣

ArrayList<Object> routeList = getWmRoute(); 
    ArrayList<HashMap<String,String>> alist=new ArrayList<HashMap<String,String>>(); 

    for(int i = 0; i<routeList.size();i++){ 
     HashMap<String, String> map = new HashMap<String, String>(); 
     map.put("RetailerCode", ((WMRoute) routeList.get(i)).getDescription()); 
     map.put("RetailerName", ((WMRoute) routeList.get(i)).getBusinessUnit()); 
     alist.add(map); 
    } 

    ListView list= getListView(); 
    sd = new SimpleAdapter(this,alist,R.layout.retalier_rows,new String[]{"RetailerCode","RetailerName"},new int[]{R.id.retailerCode,R.id.retailerName}); 
    list.setAdapter(sd); 
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
    list.setSelected(true); 
    list.setSelection(0); 
    list.setTextFilterEnabled(true); 
    list.setItemsCanFocus(true); 
    list.setTextFilterEnabled(true); 
    list.setItemChecked(positions,true); 

和XML文件創建(retalier_rows.xml)進行

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

<TextView android:text="RetailerCode" 
      android:id="@+id/retailerCode" 
      android:layout_width="125dp" 
      android:layout_height="35dp"> 

<TextView android:text="RetailerName" 
      android:layout_width="125dp" 
      android:layout_height="35dp" 
      android:id="@+id/retailerName" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@+id/retailerCode" 
      android:layout_marginLeft="15dp" 
      android:layout_alignParentRight="true"></TextView> 

如果你需要3列,你可以添加新的&代碼也可以指定

相關問題