跳过 1 时,CursorWrapper 正在复制行

CursorWrapper is duplicating row when skipping over 1

我正在隐藏具有特定 employee_number 的行,现在当我这样做时,被跳过的行将使用它之前的行中的数据进行填充。不确定如何避免重复并跳过它?

CustomCursorWrapper.java:

public class CustomCursorWrapper extends CursorWrapper {

    private String mStartingEmployeeID = "startingNumber";
    Employee employee;


    public CustomCursorWrapper(Cursor cursor) {
        super(cursor);
    }

    @Override
    public int getCount() {

        //if you want to exclude just one row
        return super.getCount() - 1;
    }

    @Override
    public boolean moveToPosition(int position) {
        if(!super.moveToPosition(position))
            return false;

        if(mStartingEmployeeID.equals(getString(getColumnIndex("Employee_number")))) {
            //if this is the row you wanna skip
            return super.moveToPosition(position + 1);
        }
        Log.d("WRAPPER", String.valueOf(position));
        return true;
    }
}

此外,当我查看我放置在这里的日志时,位置返回为:

01-31 20:57:58.984 5533-5533/com.example.agar098.oneteam D/WRAPPER: 0
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 0
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 1
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 1
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 1
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 2
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 2
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 2
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 3
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 3
01-31 20:57:59.004 5533-5533/com.example.agar098.oneteam D/WRAPPER: 3
01-31 20:57:59.014 5533-5533/com.example.agar098.oneteam D/WRAPPER: 4
01-31 20:57:59.014 5533-5533/com.example.agar098.oneteam D/WRAPPER: 4
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 4
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 0
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 0
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 0
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 1
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 1
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 1
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 2
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 2
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 2
01-31 20:57:59.024 5533-5533/com.example.agar098.oneteam D/WRAPPER: 3
01-31 20:57:59.034 5533-5533/com.example.agar098.oneteam D/WRAPPER: 3
01-31 20:57:59.034 5533-5533/com.example.agar098.oneteam D/WRAPPER: 3
01-31 20:57:59.034 5533-5533/com.example.agar098.oneteam D/WRAPPER: 0
01-31 20:57:59.034 5533-5533/com.example.agar098.oneteam D/WRAPPER: 0
01-31 20:57:59.034 5533-5533/com.example.agar098.oneteam D/WRAPPER: 0
01-31 20:57:59.034 5533-5533/com.example.agar098.oneteam D/WRAPPER: 1
01-31 20:57:59.044 5533-5533/com.example.agar098.oneteam D/WRAPPER: 1
01-31 20:57:59.044 5533-5533/com.example.agar098.oneteam D/WRAPPER: 2
01-31 20:57:59.044 5533-5533/com.example.agar098.oneteam D/WRAPPER: 2
01-31 20:57:59.044 5533-5533/com.example.agar098.oneteam D/WRAPPER: 3
01-31 20:57:59.054 5533-5533/com.example.agar098.oneteam D/WRAPPER: 3
01-31 20:58:16.174 5533-5533/com.example.agar098.oneteam D/WRAPPER: 4
01-31 20:58:16.194 5533-5533/com.example.agar098.oneteam D/WRAPPER: 4
01-31 20:58:16.944 5533-5533/com.example.agar098.oneteam D/WRAPPER: 6
01-31 20:58:16.944 5533-5533/com.example.agar098.oneteam D/WRAPPER: 6
01-31 20:58:16.944 5533-5533/com.example.agar098.oneteam D/WRAPPER: 6
01-31 20:58:17.214 5533-5533/com.example.agar098.oneteam D/WRAPPER: 7
01-31 20:58:17.214 5533-5533/com.example.agar098.oneteam D/WRAPPER: 7
01-31 20:58:17.214 5533-5533/com.example.agar098.oneteam D/WRAPPER: 7
01-31 20:58:17.804 5533-5533/com.example.agar098.oneteam D/WRAPPER: 8
01-31 20:58:17.804 5533-5533/com.example.agar098.oneteam D/WRAPPER: 8
01-31 20:58:17.804 5533-5533/com.example.agar098.oneteam D/WRAPPER: 8
01-31 20:58:17.954 5533-5533/com.example.agar098.oneteam D/WRAPPER: 9
01-31 20:58:17.954 5533-5533/com.example.agar098.oneteam D/WRAPPER: 9
01-31 20:58:17.954 5533-5533/com.example.agar098.oneteam D/WRAPPER: 9

最佳和正确的解决方案是使用 SQLite 过滤子句语句查询数据库以排除不需要的行。这样,您就不必编写一堆技巧来跳过一行。

例如

getReadableDatabase().rawQuery("SELECT * FROM TABLE_NAME WHERE COLUMN != employeeId",null);

将 return 游标包含除与传入的员工 ID 匹配的行之外的所有行。