2011-08-12 5 views
0

listview.That 행에서 특정 행에 대한 색상을 설정하려는 런타임에 알 수 있습니다. 나는이 같은 목록보기를 수행 ahve :안드로이드 setcolour listview 특정 행 (단 하나의 특정 행)

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(); 

내가이 작업을 수행 할 수있는 방법을 가르쳐주세요 ... 사전에

감사를

답변

1

한 가지 방법은 당신이 원하는 행의 인덱스를 사용하는 것입니다 getgetListView(). getChildAt (index) .setBackground (# ff0000);

그렇지 않으면 사용자 정의 어댑터를 작성하고 각 행을 렌더링하기 전에 호출되는 getView 메소드를 겹쳐 써야합니다. 이를 사용하여 조건을 확인하고 그에 따라 배경을 설정할 수 있습니다. http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

위의 내용은 자습서입니다.