0

Hi i am new in Android Sqlite Database. I want to parse all my values from a Sqlite column to an Array. It look's like folllowing:

id        name
1         Peter
2         Mary
3         Tom
4         Elsa

Android Array:

String[] NameArray = new String[4];
Int[] idArray = new Int[4];
1
  • 2
    Show us your efforts! What've you tried already? Commented Mar 19, 2015 at 10:30

1 Answer 1

2
            String Table_Name="name of table";
            String selectQuery = "SELECT  * FROM " + Table_Name;
            SQLiteDatabase db = this.getReadableDatabase();
            Cursor cursor = db.rawQuery(selectQuery, null);
            cursor.moveToFirst();
            String[] NameArray = new String[cursor.count()];
            String[] idArray = new String[cursor.count()];
            int i = 0;

            while(cursor.moveToNext()){

                String uname = cursor.getString(cursor.getColumnIndex("name"));
                NameArray [i] = uname;
                String id= cursor.getString(cursor.getColumnIndex("id"));
                idArray [i] = id;
                i++;

            }
            db.close();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.