开发者

Android setcolour listview particular row (only one particular row)

开发者 https://www.devze.com 2023-03-27 21:15 出处:网络
I want to set color for particular row in listview.That row will know at runtime. I ahve done list view like this :

I want to set color for particular row in listview.That row will know at runtime. I ahve done list view like this :

 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);
    getLis开发者_Python百科tView().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();

Please tell me how can i do this...

Thanks in advance


One way is to use the index of the row you want to get like getListView().getChildAt(index).setBackground(#ff0000);

Otherwise you would need to create a custom adapter and overwrite the getView method which is called before rendering each row. You can use that to check any conditions and set the background accordingly. http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

The above is a tutorial about that.

0

精彩评论

暂无评论...
验证码 换一张
取 消