Reputation: 353
Im in the middle of a project and am a little bit stuck. I have an image viewer that takes an array of URL's and puts out a gallery of pictures. All that works great. What I am struggling with is instead of having it use pre determined links, have it use the links from my database. When I call the database I get a result something like this "name":" "http://lh6.googleusercontent.com/-jZgveEqb6pg/T3R4kXScycI/AAAAAAAAAE0/xQ7CvpfXDzc/s1024/sample_image_01.jpg" Im not sure how to be able to use this result and put it into my image viewer. Right now all the URLs are in an array and my query is an array list. This is another thing that is confusing me
ArrayList<String> list = new ArrayList<String>();
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
list.add(jArray.get(i).toString());
}
Thats my query call and how I get my array list. Any pointers or suggestions would be appreciated.
Upvotes: 0
Views: 193
Reputation: 2683
So, you want to use pre-defined data (from database) to populate your picture gallery. First you have to get cursor out from database and looping through all rows and add to arraylist
//Get db crusor
Cursor cursor = db.rawQuery("SELECT * FROM table", null);
ArrayList<String> list = new ArrayList<String>();
// looping through all rows and adding to Arraylist
if (cursor.moveToFirst()) {
do {
//get string from database cursor and add it to arraylist
list.add(cursor.getString(1));
} while (cursor.moveToNext());
}
This link can help you to understand using database in android
Upvotes: 1
Reputation: 5453
Is it that you want? Iterate the list?
for (String url : list) {
// Do something with url
}
Upvotes: 1