ORMLite with CursorAdapter in Android

前端 未结 3 1801
花落未央
花落未央 2020-12-09 18:35

I am modifying my Android app to work with ORMLite, and it currently uses a number of CursorAdapters, which I quite want to keep in an attempt to minimise coding.

I\

3条回答
  •  醉酒成梦
    2020-12-09 19:24

    Wrap your cursor with another one that treats "_id" as an alias to your real primary key column. Example:

    cursor = new CursorWrapper(cursor) {
                    @Override
                    public int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException {
                        if ("_id".equals(columnName)) columnName = "id";
                        return super.getColumnIndexOrThrow(columnName);
                    }
                };
    

提交回复
热议问题