0
即时通讯新的机器人编程和我有一个简单的检索图像从网址工作,但困惑如何使它,所以我可以从我的网页加载多个图像的网址。有人告诉我,改变绘制到字符串,但不是100%肯定该怎么办所以这里是大多数到目前为止我的代码:如何让多个url链接显示在数组中?
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;
}
}
}
感谢您的回答rpond即时试图初始化它,让它做的工作,我需要去.XML和定义<字符串数组,或只是一个普通的阵列的工作?我想我可能已经把它在右侧部分只是不显示现在。不完全知道我在哪里丢失了围绕IamgeView的代码。 – user305307 2010-03-30 23:23:19
如果网址是静态的,你可以将它放入资源中的字符串数组中。如果网址是动态的,那么您需要创建一个String []数组或列表来迭代。 –
2010-03-31 13:01:10
我应该把它放在一个arrays.xml中,然后我完全失去了如何将我的代码与你的代码混合在一起。你知道任何好的教程,同时做出一个选项滑过侧面浏览网址。 – user305307 2010-03-31 19:51:06