开发者

How do i make multiple url links show in array?

Im new to droid programming and i got a simple retrieve imag开发者_JAVA技巧e from url working but confused on how to make it so i can load multiple images from my webpages url. Someone informed me change the drawable to string but not sure 100% how to do so here is most of my code so far:

public class Gallery extends Activity {
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

        ImageView imgView =(ImageView)findViewById(R.id.ImageView01);
        Drawable drawable = LoadImageFromWebOperations("http://www.mandarichmodels.com/hot-pics/4.jpg", "http://www.mandarichmodels.com/hot-pics/5.jpg");
    imgView.setImageDrawable(drawable);

}

   private Drawable LoadImageFromWebOperations(String url, String string) {
      try
        {
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
        }catch (Exception e) {
            System.out.println("Exc="+e);
            return null;
        }
    }
}


Create an Array or List of the URLS you want to pull from, and then use that same code you have but put it into a loop over the length of the Array or List. And you should do this in a separate thread so that you don't generate an ANR. Look up AsyncTask.

List<String> urls;
for(int i=0; i<urls.size(); i++) {
    Drawable d = LoadImageFromWebOperations(urls.get(i));
    // do something interesting
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜