跳过1时,CursorWrapper正在重复行

时间:2017-02-01 15:16:10

标签: android android-cursor

我正在隐藏一个具有特定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

1 个答案:

答案 0 :(得分:1)

最好和最合适的解决方案是使用SQLite过滤器子句语句查询数据库以排除您不想要的行。这样,你就不必编写一堆黑客来跳过一行。

例如

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

将返回一个光标,其中包含与传入的员工ID匹配的所有行。