I'm trying to translate my app from Java to Kotlin. I'm managing database with AnKo SQLite
All is OK except listviews with CursorLoaders : I can't find how to replace CursorLoader while using AnKo SQLite. (and same problem with expandableListViews)
Can somebody help me please?
OK, here is my solution... I don't know if it is the best :
set the primary constructor like this :
class MyCursorLoader( mContext: Context, val mTableName: String, var mProjection: Array<String>? = null, var mSelection: String = "1", var mSelectionArgs: Array<String> = emptyArray(), var mGroupBy: String = MySqlHelper.ID, var mHaving: String = "", var mSortOrder: String = "${MySqlHelper.ID} ASC", var mLimit: String = "", var mDistinct: Boolean = true ): CursorLoader(mContext) { val mObserver: Loader<Cursor>.ForceLoadContentObserver = Loader<Cursor>(mContext).ForceLoadContentObserver() var mCancellationSignal: CancellationSignal? = nulloverride the OnLoadInBackground method with te same code than built-in one, just replacing the
val cursor = ContentResolverCompat.query(...line with :So no need to recreate a dataprovider in manifest, no need to deal with Uri's... I can use MyCursorLoader exactly like built-in CursorLoader, calling it like this :
Let me know if ther is a better solution.
Hope that can help.