Last active
December 27, 2020 11:27
-
-
Save Meraj/88c9770ac6cac3aba4a3cd2ed19e76e8 to your computer and use it in GitHub Desktop.
a simple function that auto convert cursors to array in kotlin - android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* a simple function that convert cursors to String Array | |
* ArioSql = https://github.com/MerajV/ArioSql | |
* @property cursor Cursor | |
* @return Array<Array<String>> | |
* @author MerajV | |
* @since 0.3.12 | |
*/ | |
fun convertCursorToArray(cursor: Cursor): Array<Array<String>> { | |
val getColumnsCount :Int = cursor.columnCount | |
var cursorArray :Array<Array<String>> = arrayOf<Array<String>>() | |
var columns :Array<String> = arrayOf<String>() | |
var indexes = 0 | |
cursor.count | |
if(cursor.count != 0){ | |
if(cursor.count == 1){ | |
cursor.moveToFirst() | |
for (i in 0 until getColumnsCount step 1){ | |
val list: MutableList<String> = columns.toMutableList() | |
list.add(cursor.getString(i)) | |
columns = list.toTypedArray() | |
} | |
val list: MutableList<Array<String>> = cursorArray.toMutableList() | |
list.add(columns) | |
cursorArray = list.toTypedArray() | |
}else{ | |
while (cursor.moveToNext()){ | |
for (i in 0 until getColumnsCount step 1){ | |
val list: MutableList<String> = columns.toMutableList() | |
list.add(cursor.getString(i)) | |
columns = list.toTypedArray() | |
} | |
val list: MutableList<Array<String>> = cursorArray.toMutableList() | |
list.add(columns) | |
cursorArray = list.toTypedArray() | |
columns = arrayOf() | |
indexes++ | |
} | |
} | |
} | |
return cursorArray | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment