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