如何在阵列中显示多个url链接?

时间:2010-03-30 16:46:49

标签: android arrays drawable url-link

我是droid编程的新手,我从url工作中获得了一个简单的检索图像,但对如何制作它感到困惑,所以我可以从我的网页网址加载多个图像。有人告诉我将drawable更改为字符串但不确定100%如何这样做这里是我目前的大部分代码:

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

1 个答案:

答案 0 :(得分:1)

创建要从中提取的URL的数组或列表,然后使用相同的代码,但将其放入数组或列表长度的循环中。你应该在一个单独的线程中执行此操作,这样就不会生成ANR。查找AsyncTask。

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