How to hide specific rows of a Cursor in android

跟風遠走 提交于 2019-12-07 06:45:43

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/2700172/how-to-hide-specific-rows-of-a-cursor-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!