java - Image from URL using SimpleAdapter -
I am using this code to get data from JSON
public Class ShowContacts ListActivity {Personal Static String URL = "http://192.168.0.103/contacts.json" Expands; Personal Static Last String TAG_CONTACTS = "Contact"; Private static final string TAG_NAME = "name"; Private static final string TAG_IMAGE = "image"; JSONArray contact = null; Int index = 0; Array list & lieutenant; Hashmap & lt; String, string & gt; & Gt; contact list; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); setContentView (R.layout.showjson); Contact List = New Arrestist & lt; Hashmap & lt; String, string & gt; & Gt; (); New GetContacts () carry about (); } Private Class GetContacts AsyncTask and lt; Zero, zero, zero> {@Override Safe Volume Doine Background (Zero ... arg0) {ServiceHandler sh = new ServiceHandler (); String jsonStr = sh.makeServiceCall (url, ServiceHandler.GET); Log D. ("Response:", ">" + jsonStr); If (jsonStr! = Null) {try {JSONObject jsonObj = New JSONObject (jsonStr); Contact = jsonObj.getJSONArray (TAG_CONTEdits); For (int i = 0; i & lt; contacts.length (); i ++) {JSONObject c = contacts.getJSONObject (i); String name = c.getString (TAG_NAME); String image = C.GreatString (TAG_IMAGE); Hashmap & lt; String, string & gt; Contact = new hashmap & lt; String, string & gt; (); Contact.put (TAG_NAME, name); Contact.put (TAG_IMAGE, image); ContactList.add (contact); }} Grip (JasonXExpress E) {e.printStackTrace ();}} Return Null; } @Override Secure Zero on postexec (zero result) {super.onPostExecute (results); String [] = {TAG_NAME, TAG_IMAGE}; For Int [] = {R.D. Names, R.D.I.J.}; List Adapter Adapter = New Simple Adapter (From ShowContacts.this, contactList, R.layout.list_item, from); setListAdapter (adapter); }}} I want to get name and image from JSON I am getting the name and it is appearing on the list, but I can not get the image. This is my JSON:
{"contact": [{"name": "John Smith", "Image": "http://192.168.0.103/image1.png"}, {"Name": "John Wayne", "Image": "http://192.168.0.103/image2.png"}]} I think it's not working Because the image is online and tries to add it as a drawer . I'm not sure how to do this, is there any way?
You want to download the image using lazy loading and loading ImageView . You can not directly parse the image directly and load the URL in the ImageView . Use the concept of or
test simple demostration
Comments
Post a Comment