0

I have an a String Array called Collections.

String[] Collections; 

I have integer values saved in my db table. I want to grab the integer values from my database column called specific_collections.

and set that to an integer array SpecificCollections.

So, I want to set it up like this:

String[] Collections = 0; Integer[] SpecificCollections = getColumnValuesFromSpecificCollectionsColumn(); 

After I set them to an integer array, I want to parse the integer array and save each int value to my String Array that is something of the form below:

Collections = new String[]{Collection.SpecificCollections.fromInt(SpecificCollections[i]).getString()}; 

where Specific Collections is the array of integers from db.

EDIT: Here's what I have so far but it's only populating the list with one int?

ArrayList<Integer> regionList= new ArrayList<Integer>(); Cursor cursorTwo = sqLiteDatabase.rawQuery("SELECT DISTINCT region FROM collection", null); if (cursorTwo != null && cursorTwo.getCount() != 0) { cursorTwo.moveToFirst(); while (!cursorTwo.isAfterLast()) { regionList.add(cursorTwo.getInt(0)); cursorTwo.moveToNext(); } } for (Integer inte : regionList){ regions = new String[]{Collection.Regions.fromInt(inte).getString()}; } 

Is below the correct way to iterate through an array list and pass the distinct integers inside the fromInt() method?

1 Answer 1

2

In the SQLiteDatabase.query() method, set selection and selectionArgs parameters to null. see the following code for example:

String[] projection = { COLUMN_NAME } Cursor cursor = mSQLiteDb.query(TABLE_NAME, projection, null, null, null, null, null); ArrayList<Integer> values = new ArrayList<Integer>(); if (cursor != null && cursor.getCount() != 0) { cursor.moveToFirst(); while (!cursor.isAfterLast()) { values.add(cursor.getInt(cursor.getColumnIndex(COLUMN_NAME))); cursor.moveToNext(); } } 
Sign up to request clarification or add additional context in comments.

9 Comments

Can you show me how to query using cursor? I tried a few solutions but none are working. Only the last value is shown. I tried this solution but doesn't work: stackoverflow.com/questions/19852821/…
hmmm, can you explain how it doesn't work? any error messages or something? I updated my answer, please try the code.
What is setNumValue? What should be myObject in this case?
You can ignore myObject, i added it to show you that you can store the columns' returned values anywhere. I updated the code again and replaced myObject with an arraylist of integers
do not forget to close cursor.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.