2011-08-12 5 views

答えて

1

一つの方法は、あなたがしたい行のインデックスを使用することで、事前に

感謝を

ArrayList<SalesRoutes> routeList = getSalesRoute(); 

    ArrayList<HashMap<String, String>> routhPath = new ArrayList<HashMap<String, String>>(); 
    for (int i = 0; i < routeList.size(); i++) { 
     if(Integer.parseInt(routeList.get(i).getOutlets()) >0){ 
      HashMap<String, String> map = new HashMap<String, String>(); 
      map.put("routeCode",((SalesRoutes) routeList.get(i)).getRouteCode()); 
      map.put("routeName",((SalesRoutes) routeList.get(i)).getDescription()); 
      map.put("outlets", ((SalesRoutes) routeList.get(i)).getOutlets()); 
      routhPath.add(map); 
     } 
    } 

    ListView list = getListView(); 
    sd = new SimpleAdapter(this, routhPath, R.layout.route_path,new String[] {"routeCode","routeName","outlets" },new int[] { R.id.routeCode,R.id.routeName,R.id.outlets}); 
    row = getLayoutInflater().inflate(R.layout.route_path_row, null, false); 
    getListView().addHeaderView(row); 
    list.setAdapter(sd); 
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
    list.setSelected(true); 
    //list.setSelection(0); 

    list.setTextFilterEnabled(true); 
    list.setItemsCanFocus(true); 
    list.setItemChecked(positions, true); 
    list.setSelectionAfterHeaderView(); 

:私はこのようなリストビューを行ってahve getuchView()。getChildAt(index).setBackground(#ff0000); のようになります。

それ以外の場合は、カスタム・アダプターを作成し、各行のレンダリング前に呼び出されるgetViewメソッドを上書きする必要があります。これを使って条件をチェックし、それに応じて背景を設定することができます。 http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

上記はチュートリアルです。

関連する問題