0

how to retrieve all images in MySQL to android really I can retrieve data like (names,ages,....) but really I can't retrieve all images whereas I have a table in MySQL contain (name , age,Image)

thanks for any guide and any help

Shanaz K
  • 678
  • 2
  • 13
  • 28

2 Answers2

2

i'm not sure this will helpful or not but you cant try this. http://www.androidbegin.com/tutorial/android-json-parse-images-and-texts-tutorial/

0

Probably you should consider to store the images in the local storage (instead of in a binary format, which is how it seems you are doing it, from your question), and in your database just store the file location. This way you shouldn't have problems converting the data from and to the database, and the database size wouldn't grow too much.

Then in your list view's adapter, you'll only need to retrieve the image's location and load it into the view you want to display.

EDIT

As I understood, you are sending the data to the Android device via Json. So let's assume you are sending a Json array like this one:

[{"username":"John", "userimage":"http://example.com/images/imagejohn.jpg"},
 {"username":"Michael", "userimage":"http://example.com/images/imagemike.jpg"},
 {"username":"Sophia", "userimage":"http://example.com/images/imagesophia.jpg"}]

So what you need is to read the JSON contents to an Array and fill it in an adapter. As I mentioned in the comments, you should take a look to the answer here: https://stackoverflow.com/a/8113337/1991053

Basically, you can read the JSON Array and put it into the ListView's Array Adapter, in the example above, you can retrieve each element like this:

JSONArray jsonArray = new JSONArray(input) // input is the JSON string you recieve
for(int i = 0; i < jsonArray.length(); i++) {
    String userName = jsonArray.optJSONObject(i).getString("username");
    String imageURL = jsonArray.optJSONObject(i).getString("userimage");
    // Here you can do whatever you want with the values
    // like loading an imageview with the url's data
    // or putting the values in an ArrayList for filling up the ListView adapter
}

Of course you can modifiy this to fit in whatever the JSON structure you are using for sending the data, just use JSONObjects and JSONArray for this. Take a look to the documentation here: JSONArray, JSONObject

If you want more control over the JSON data (like serialize or deserialize the data), take a look to Jackson or Gson. There are plenty of examples around to understand how they work.

But I think your best bet is to use the adapter shown Here. Also, for loading up images in a ListView from a URL, you can use this library: Lazy List.

Hope this helps you for a start. Best regards.

Community
  • 1
  • 1
Dr NotSoKind
  • 225
  • 1
  • 5
  • 14
  • Pnikosis really I made an API which is php and android when someone upload some status on php part which is web site I wanna show a notification on android part so my tables should be on localhost – Shanaz K Oct 06 '13 at 10:25
  • Oh, sorry, I think I misunderstood the question, you mean an external mysql database? So then it notifies the Android device by sending the image and other data? – Dr NotSoKind Oct 06 '13 at 10:32
  • :) yeah you're right I wanna see who posted (name and image ) on my android device it's easy for retrieving name but image I can't :( – Shanaz K Oct 06 '13 at 10:38
  • Oh, in that case, just send the name and the image's URL to the Android device. Then load the image from the URL. – Dr NotSoKind Oct 06 '13 at 10:46
  • look you're right this is just right for retrieving single data I wanna retrieve all name with images I wanna put all data in listview – Shanaz K Oct 06 '13 at 10:50
  • OK, now I get it. You are sending a JSON array with all the data. You need to convert the JSON object to something that could be inserted in the list view. In that case, check this answer http://stackoverflow.com/questions/6277154/populate-listview-from-json or check a library for reading JSON objects such as Jackson – Dr NotSoKind Oct 06 '13 at 11:02
  • sorry what is Jackson ? – Shanaz K Oct 06 '13 at 11:07
  • Is a JSON processor, it can help you to create java objects from JSON, so you could create an arraylist based on your JSON object to fill in your listview. Check http://jackson.codehaus.org/, also you can check Google's Gson, for the same purposes. – Dr NotSoKind Oct 06 '13 at 11:11
  • sorry any video link? it's better for me – Shanaz K Oct 06 '13 at 11:14
  • Right now I'm on the mobile, so it's quite hard for me to find any tutorials at this moment. If you want, edit your question showing the JSON string you want to use to fill in the list view, and later (in some hours) I'll help you to convert it to something that can used to fill in the data (if nobody else hasn't answered yet) – Dr NotSoKind Oct 06 '13 at 11:24
  • Sorry, I don't know if there's a video explaining this somewhere. – Dr NotSoKind Oct 10 '13 at 17:01