0

I want to list text and image from json which is placed in particular url

I have successively displayed textview but how to display image my code is

public class AndroidJSONParsingActivity extends ListActivity {


    // url to make request
    private static String url = "***MY URL***";

    // JSON Node names

    private static final String TAG_ID = "id";
    private static final String TAG_NAME = "name";
    private static final String TAG_PRICE = "price";
    private static final String TAG_URL = "hosting_thumbnail_url";


    // contacts JSONArray


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_jsonparsing);

        // Hashmap for ListView
        ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

        // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();

        // getting JSON string from URL
        JSONArray json = jParser.getJSONFromUrl(url);

        try {
            // Getting Array of Contacts


            // looping through All Contacts
            for(int i = 0; i < json.length(); i++){
                JSONObject c = json.getJSONObject(i);

                // Storing each json item in variable
                String id = c.getString(TAG_ID);
                String name = c.getString(TAG_NAME);
                String email = c.getString(TAG_PRICE);
                //String  image1 = c.getString( TAG_URL);

                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                map.put(TAG_ID, id);
                map.put(TAG_NAME, name);
                map.put(TAG_PRICE, email);
                //map.put(TAG_URL, image1);


                // adding HashList to ArrayList
                contactList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        /**
         * Updating parsed JSON data into ListView
         * */
        ListAdapter adapter = new SimpleAdapter(this, contactList,
                R.layout.list_item,
                new String[] { TAG_NAME, TAG_PRICE }, new int[] {
                        R.id.name, R.id.email });

        setListAdapter(adapter);


    }

}

i want listview like this "http://pic002.cnblogs.com/images/2012/372551/2012021011374176.jpg"

2 Answers 2

2

You will need to write a custom list adapter. Google for "android custom listadapter image". The first hit is this one, which looks like a decent example.

Sign up to request clarification or add additional context in comments.

Comments

0

As SimonSays said, you have to implement your own ListView adapter class and its getView() method.

If you plan to obtain these JSON objects dynamically in ListView I strongly recommend to use some Thread mechanism, that would set data from that JSON object to ListView immediately when it's obtained - i.e. AsyncTask

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.