下面是我嘗試將圖像下載到Android應用程序內的活動。我的應用程序崩潰在行img1.setImageDrawable(d);我有一個LinearLayout裏面的RelativeLayout ..不知道爲什麼這會一直崩潰..我需要總共四個圖像下載到活動,我是否正確設置xml以獲得四個圖像或我需要對於個人ImageView的?任何建議/想法/提示,非常感謝。從Android中的線程下載圖像
Thread t = new Thread(){
@Override
public void run(){
int i = imgarr.length;
int j = 0;
while(j<i){
try {
InputStream is = (InputStream) new URL(imgarr[j]).getContent();
Drawable d = Drawable.createFromStream(is,"pic");
img1.setImageResource(d);
j++;
} catch (MalformedURLException e) {}
catch (IOException e) {}
}
}//end run
};
t.start();
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@id/adbody"
>
<ImageView android:id="@+id/image1" android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingTop="15dip"/>
</LinearLayout>
logcat關於崩潰的說法是什麼?什麼是錯誤? –
這些文件是否已經存儲在本地?基本上,imgarr充滿了文件路徑? –
@ B.Young imgarr充滿了IMG的網址... – Andrew