在Scrollable ListView中,listView.setSelection()之后的getChildAt()。setBackgroundColor()

时间:2015-03-11 15:12:04

标签: android android-fragments android-listview

我创建了一个Fragment,我在其中使用SimpleAdpater填充可滚动的ListView。我使用
向下滚动到ListView中的项目 listView.setSelection(location_of_time_in_list);
之后我正在调用一个函数
setListviewSelection(listView,location_of_time_in_list);
更改所选项目的背景颜色(由 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);

但背景颜色没有变化。请帮助??

0 个答案:

没有答案