i have created a Fragment, in which i am populating the scrollable ListView using SimpleAdpater. I am scrolling down to a item in ListView using
listView.setSelection(location_of_time_in_list);
After that i am calling a function
setListviewSelection(listView, location_of_time_in_list);
to change background color of the selected item(selected by setSelection())
sa = new SimpleAdapter(getActivity(), arraylist, R.layout.train_column,new String[] {"location", "time", "direction", "speed"}, new int[] {R.id.TRAIN_CELL, R.id.TIME_CELL, R.id.DIRECTION_CELL, R.id.SPEED_CELL});
listView.setAdapter(sa);
listView.setSelection(location_of_time_in_list);
setListviewSelection(listView, location_of_time_in_list);
public static void setListviewSelection(final ListView list, final int pos) {
list.postDelayed(new Runnable() {
@Override
public void run() {
View v = list.getChildAt(pos);
if (v != null) {
v.setBackgroundColor(Color.CYAN);
}
}
},100);
But the background Color is not changing. Please Help??