2011-12-24 3 views
0

i m chargement des images de description rss utilisantUtilisez AsyncTask pour charger des images

String description2 = des.get(position).toString(); 

     Spanned description = Html.fromHtml(description2, new ImageGetter() { 
      @Override 
     public Drawable getDrawable(String source) {     
      Drawable d = null; 
      try { 
         InputStream src = imageFetch(source); 
         d = Drawable.createFromStream(src, "src"); 
         if(d != null){ 
     d.setBounds(0,0,d.getIntrinsicWidth(), 
     d.getIntrinsicHeight()); 
         } 
     } catch (MalformedURLException e) { 
        e.printStackTrace(); 
      } catch (IOException e) { 
        e.printStackTrace(); 
      } 

     return d; 
     } 

      public InputStream imageFetch(String source) 
        throws MalformedURLException,IOException { 
     URL url = new URL(source); 
     Object o = url.getContent(); 
     InputStream content = (InputStream)o; 
     // add delay here (see comment at the end)  
     return content; 
     } 

     },null); 

Comment puis-je les mettre dans un AsyncTask, afin d'obtenir une barre de progression jusqu'à ce que les images télécharger? Merci!

+0

Regardez [Android HTML ImageGetter comme AsyncTask] (http://stackoverflow.com/questions/7424512/android-html-imagegetter-as-asynctask) – user370305

Répondre

0

Vous pouvez consulter ce tutorial, qui télécharge des images à partir du Web et utilise la barre de progression. Tout est fait dans AsyncTask et la source complète est disponible.

0

vous pouvez utiliser cette WebImageView de generic-store-for-android

qui est adapté du projet droïde-fu.

Voici un exemple d'utilisation;
-> définir dans votre mise en page

<com.wareninja.opensource.droidfu.widgets.WebImageView 
    android:id="@+id/img_fbProfilePic" 
    android:visibility="visible" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
/> 


-> définir l'URL pour charger

WebImageView fbProfilePic = (WebImageView) this.findViewById(R.id.img_fbProfilePic); 
fbProfilePic.setImageUrl("http://graph.facebook.com/100001789213579/picture"); 
fbProfilePic.loadImage(); 
Questions connexes