3

Maintenant je travaille avec un projet Android ici, j'ai une vue de la liste de cette vue de la liste obtenir des résultats de l'API Google par classe JSON. Maintenant j'essaye d'obtenir quelques images par la variable TAG_ICON qui renvoie une URL et j'ai directement donné l'URL à l'adaptateur de liste mais pendant que j'exécutais mon projet je n'obtenais aucune image dans la disposition de vue d'image aidez-moi à résoudre ce problème et voici mon codecharger l'image à partir de l'URL et l'ajouter à la liste

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); 

      } 
     }); 

     } 

} 
} 

Répondre

1

Utilisez un élément webview personnalisé et définissez l'URL dans votre fichier java.

WebView webview = (WebView)findViewById(R.id.webview); 
webview.getSettings().setJavaScriptEnabled(true); 
webview.loadUrl(getString(R.URL.myurl)); 
Questions connexes