Mcloving
Mcloving

Reputation: 1410

change listview background colour on button press

I know how to set colours on the listview, using bindView. So when ever it is created, (or scrolled onto screen) the colour is set...

But how do I go through existing views, without destroying and re-creating the entire thing.

Aka, If i press a button, I wish to highlight all existing on screen items (in the listview) that have second field in the cursor = False

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

Edit:

Currently I do this, but it requires refreshing the cursor.

    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

Upvotes: 3

Views: 270

Answers (1)

Goran Horia Mihail
Goran Horia Mihail

Reputation: 3645

In the onClick event of the button you need to call adapter.notifyDataSetChanged() which will refresh the data in the listview and in turn will set your preferred color to the items that have the second field in the cursor == false

Upvotes: 3

Related Questions