How can I create a list Array (the list display First Alphabet when scroll) with the cursor data?
How can I create a list Array (the list display First Alphabet when scroll) with the cursor data?
In Kotlin you can use this extension:
fun <T> Cursor.toList(block: (Cursor) -> T) : List<T> {
return mutableListOf<T>().also { list ->
if (moveToFirst()) {
do {
list.add(block.invoke(this))
} while (moveToNext())
}
}
}
and use it:
val listOfIds = cursor.toList {
// create item from cursor. For example get id:
it.getLong(it.getColumnIndex("_id"))
}