进出口新的机器人编程和我有一个简单的从URL工作取得的图像,但困惑于如何使它这样我就可以从我的网页URL中加载多个图像。有人告诉我,改变绘制到字符串,但不能肯定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;
        }
    }
}
有帮助吗?

解决方案

创建要从拉,然后用你有相同的代码,但把它变成一个循环在数组或列表的长度的URL的数组或列表。你应该在一个单独的线程做到这一点,这样你就不会产生ANR。查找的AsyncTask。

List<String> urls;
for(int i=0; i<urls.size(); i++) {
    Drawable d = LoadImageFromWebOperations(urls.get(i));
    // do something interesting
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top