How we set ListView’s background for particular row.
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});
list.setAdapter(sd);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setSelected(true);
list.setTextFilterEnabled(true);
list.setItemsCanFocus(true);
list.setSelectionAfterHeaderView();
if(isVisitedToVisitHeader()){
if(defaultRoutePos != 0){
Log.i("-----" ,"---defaultRoutePos---" + defaultRoutePos +" --count-- "+list.getChildCount());
list.setItemChecked(defaultRoutePos, true);
// list.getChildAt(positions).setBackgroundColor(R.color.red);
//list.getChildAt(defaultRoutePos).setBackgroundColor(R.color.red);
}
}
this is my code .I have done using SimpleAdapter.Here list.getChildCount() give 0.This part I am ding in the onCreate() .
Please help me…
Thanks in advance
Checkout this example of Custom ListView,
Example
Also this answer of StackOverflow
StackOverflow Answer