views:

156

answers:

2

Hey,

I have a cursor, and it got, lets say, 40 rows, I want to hide some rows when the user check a checkbox.

one way is run the query again on the cursor, but it doesn't help me because the condition is done by Java (calculate balance, with many logic).

I need something that will get the current row, and return if it can be show or not.

any help will be appreciated.

A: 

Write yourself a ListAdapter that knows whether to hide/show specific rows from an adapter it wraps.

You can see examples of such wrapping adapters here and here.

CommonsWare
thanks man, i found another way, more efficient, please tell me what you think after i'll post it
Noam Shemesh
+1  A: 

i inherit CursorWrapper and override some of the methods, here is the code:

public class SelectableCursorWrapper extends CursorWrapper {

private HashSet<Integer> mWhichShow;

public SelectableCursorWrapper(Cursor cursor, HashSet<Integer> whichToShow) {
    super(cursor);

    mWhichShow = whichToShow;
}

@Override
public int getCount() {
    return mWhichShow.size();
}

@Override
public boolean moveToPosition(int position) {
    if (position >= super.getCount()) {
        return false;
    }

    if (mWhichShow.contains(position)) {
        return super.moveToPosition(position);
    } else {
        // Recursion on this method to move to the next element properly
        return this.moveToPosition(position + 1);
    }
}
}

thanks for anyone that try to help!

Noam Shemesh