SQLiteDatabase.CursorFactory 在 Android 中有什么用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11643294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:20:29  来源:igfitidea点击:

what is the use of SQLiteDatabase.CursorFactory in Android?

androidsqlite

提问by Narendra Pal

I have created a database by extending SQLiteOpenHelperclass. And its created also. This is code I am pasting

我通过扩展SQLiteOpenHelper类创建了一个数据库。它也创造了。这是我正在粘贴的代码

public Imagehelper(Context context) {
    super(context, DATABASE_NAME, null, SCHEMA_VERSION);

    cntxt = context;
    filename = Environment.getExternalStorageDirectory();

    DATABASE_FILE_PATH_EXTERNAL = filename.getAbsolutePath()+File.separator+DATABASE_NAME;
    Log.i("Log", ":"+DATABASE_FILE_PATH_EXTERNAL);
}

Here everything is working fine. But if you focus on the parameters pass in super super(context, DATABASE_NAME, null, SCHEMA_VERSION);. I am not able to understand the null parameter. I know here we have to pass the SQLiteDatabase.CursorFactoryobject.

这里一切正常。但是如果你专注于参数传入 super super(context, DATABASE_NAME, null, SCHEMA_VERSION); . 我无法理解 null 参数。我知道这里我们必须传递SQLiteDatabase.CursorFactory对象。

But how?? And what is the use of that??

但是怎么样??还有那有什么用??

回答by BBdev

The reason of passing null is you want the standard SQLiteCursorbehaviour. If you want to implement a specialized Cursoryou can get it by by extending the Cursor class( this is for doing additional operations on the query results). And in these cases, you can use the CursorFactoryclass to return an instance of your Cursor implementation. Here is the document for that

传递 null 的原因是您想要标准SQLiteCursor行为。如果要实现 aspecialized Cursor可以通过扩展Cursor class( 这是为了对查询结果执行附加操作)来获得它。在这些情况下,您可以使用CursorFactory该类返回 Cursor 实现的实例。这是文件

SQLiteDatabase.CursorFactory DOC

SQLiteDatabase.CursorFactory DOC

Used to allow returning sub-classes of Cursor when calling query.

用于在调用查询时允许返回 Cursor 的子类。