[英]How do i make multiple url links show in array?
Im new to droid programming and i got a simple retrieve image from url working but confused on how to make it so i can load multiple images from my webpages url. 我是droid编程的新手,我从url工作中获得了一个简单的检索图像,但是对如何制作它感到困惑,因此我可以从我的网页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:
有人通知我将drawable更改为string,但不确定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;
}
}
}
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. 创建要从中提取URL的数组或列表,然后使用相同的代码,但是将其放入数组或列表长度的循环中。 And you should do this in a separate thread so that you don't generate an ANR.
而且,您应该在单独的线程中执行此操作,以免生成ANR。 Look up AsyncTask.
查找AsyncTask。
List<String> urls;
for(int i=0; i<urls.size(); i++) {
Drawable d = LoadImageFromWebOperations(urls.get(i));
// do something interesting
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.