Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to display an image from JSON Object
    primarykey
    data
    text
    <p>Am beginner to android.. I want to display the text and an image from JSON... Here i can able to display the text but not the image... Can anybody help me ??</p> <pre><code>This is my JSON : { " countries":[ {"countryname":"India", "flag":"http://******.in/p/demo1/india.png" }, {"countryname":"****", "flag":"http://******.in/p/demo1/*****.png" }, ...........................................and so on ] } </code></pre> <p>Here i can display the <strong>countryname</strong>, but cant able to display the image <strong>(flag)</strong>... Country name and the flag displayed in a <strong>list view</strong>....if i click on any item, it has to show a country name and its flag in aonther activity.... i get country name but not the flag in imageview....</p> <p>Here my code :</p> <pre><code> public class AndroidJSONParsingActivity extends ListActivity { // url to make request private static String url = "http://*****@#$$$@#$.in/p/demo1/first.php/countries"; // JSON Node names private static final String TAG_COUNTRIES = "countries"; private static final String TAG_COUNTRYNAME = "countryname"; private static final String TAG_FLAG= "flag"; JSONArray countries = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Hashmap for ListView ArrayList&lt;HashMap&lt;String, String&gt;&gt; contactList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); // Creating JSON Parser instance JSONParser jParser = new JSONParser(); // getting JSON string from URL JSONObject json = jParser.getJSONFromUrl(url); try { // Getting Array of Contacts countries = json.getJSONArray(TAG_COUNTRIES); // looping through All Contacts for(int i = 0; i &lt; countries.length(); i++){ JSONObject c = countries.getJSONObject(i); // Storing each json item in variable String name = c.getString(TAG_COUNTRYNAME); String flag= c.getString(TAG_FLAG); // creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); // adding each child node to HashMap key =&gt; value map.put(TAG_COUNTRYNAME, id); map.put(TAG_LANGUAGE, name); map.put(TAG_CAPITAL, email); // adding HashList to ArrayList contactList.add(map); } } catch (JSONException e) { e.printStackTrace(); } ListAdapter adapter = new SimpleAdapter(this, contactList,R.layout.list_item, new String[] { TAG_COUNTRYNAME, TAG_FLAG}, new int[] { R.id.country_name, R.id.flag}); setListAdapter(adapter); // selecting single ListView item ListView lv = getListView(); // Launching new screen on Selecting Single ListItem lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // getting values from selected ListItem String country_name = ((TextView) view.findViewById(R.id.countyr_name)).getText().toString(); String flag= ((ImageView) view.findViewById(R.id.flag)).getTag().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class); in.putExtra(TAG_COUNTRYNAME, country_name); in.putExtra(TAG_FLAG, flag); startActivity(in); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload