我是新手,我有一個問題,我想用函數處理程序運行圖像,但我失敗了,像這樣的代碼上運行圖像的代碼是什麼?可以幫助我解決這個問題嗎?如何使用處理程序運行圖像
Intent intent = getIntent();
String url= intent.getStringExtra("URL");
tombol2 = (Button) findViewById(R.id.button2);
iv = (ImageView) findViewById(R.id.imageView1);
Drawable d1=LoadImageFromWebOperations(url);
iv.setImageDrawable(d1);
}
private Drawable LoadImageFromWebOperations(String url)
{
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;
}
}
}
你會得到強制關閉嗎?你的應用崩潰了嗎? – Raghunandan
如果我給代碼處理程序的內部代碼我得到錯誤,我不知道如何使圖像可以運行 –
你做得不對。如果你從url獲得你應該使用一個線程或asynctask – Raghunandan