按钮按下更改列表视图背景颜色

时间:2014-05-02 13:20:24

标签: android listview android-listview highlight

我知道如何使用bindView在listview上设置颜色。因此,当它被创建(或滚动到屏幕上)时,颜色就会被设置......

但是,如何在不破坏和重新创建整个视图的情况下浏览现有视图。

Aka,如果我按一个按钮,我希望突出显示在光标中有第二个字段的所有现有屏幕项目(在列表视图中)= False

Item 1, True
Item 2, True
Item 3, False -- Should highlight Green on button press.
Item 4, True

编辑:

目前我这样做,但需要刷新光标。

    int currentPosition = lv.getFirstVisiblePosition(); // Obtain where list is
    lv.setAdapter(null);


    Cursor cursor = SqlDB.getCursor();
    adap = new MyAdaptor(this, R.layout.list, cursor, columns, to, true, 0);

    lv.setAdapter(adap);
    lv.setSelection(currentPosition); // Move back to where it was

1 个答案:

答案 0 :(得分:3)

在按钮的onClick事件中,您需要调用adapter.notifyDataSetChanged(),它将刷新列表视图中的数据,然后将首选颜色设置为在游标中具有第二个字段的项目== false < / p>