Question

Now i am working with an android project here I've a list view that list view getting some results from the Google API by JSON class. Now i am trying to get some images through the TAG_ICON variable which returns a URL and i directly given the URL to the list adapter but while running my project i didn't get any image in the image view layout please help me to fix this problem and here is my code

public class MyListActivity extends ListActivity {

    // JSON Node names
                private static final String TAG_CONTACTS = "results";
                private static final String TAG_ID = "id";
                private static final String TAG_NAME = "name";
                private static final String TAG_GENDER = "rating";
                private static final String TAG_REFERENCE = "reference";
                private static final String TAG_ICON = "icon";

    // contacts JSONArray
    JSONArray result = null;

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

        // url to make request

        Intent in = getIntent();
         String location = in.getStringExtra("TAG_LOCATION");
         String type = in.getStringExtra("TAG_TYPE");
        url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query="+type+"+in+"+location+"&sensor=true&key=AIzaSyD38pak_katUfSR92WE2_O2b9y0JSp5htA";
        //}

    new LoadData().execute();

    }

class LoadData extends AsyncTask<String, String, String>
    { 

    // Hashmap for ListView
        ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
    protected String doInBackground(String... args) {


        // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();
        // getting JSON string from URL

        JSONObject json = jParser.getJSONFromUrl(url);
        RatingBar myratingbar = (RatingBar)findViewById(R.id.ratingbar);

        try {
            // Getting Array of Contacts
            result = json.getJSONArray(TAG_CONTACTS);
            // looping through All Contacts
            for(int i = 0; i < result.length(); i++){
                JSONObject c = result.getJSONObject(i);

                // Storing each json item in variable
                String id = c.getString(TAG_ID);
                String name = c.getString(TAG_NAME);
                String icon = c.getString(TAG_ICON);

            // 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_ICON, icon);

                // adding HashList to ArrayList
                contactList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
            }    
        protected void onPostExecute(String file_url) {

        /**
         * Updating parsed JSON data into ListView
         * */
        ListAdapter adapter = new SimpleAdapter(MyListActivity.this, contactList,
                R.layout.listview_item_row,
                new String[] {TAG_ICON,TAG_NAME}, new int[] {
                        R.id.imgIcon,R.id.txtTitle});

        setListAdapter(adapter);

        // selecting single ListView item
        ListView lv = getListView();

        // Launching new screen on Selecting Single ListItem
        lv.setOnItemClickListener(new OnItemClickListener() {


            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                // Starting new intent
                Intent in = new Intent(getApplicationContext(), ProfileViewActivity.class);
                startActivity(in);

            }
        });

        }

}
}
Was it helpful?

Solution

Use a custom webview element and set url in your java file.

WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(getString(R.URL.myurl));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top