どのように私は、複数のURLリンクが配列で表示するのですか?
質問
ドロイドプログラミングに新しいイムと私は単純な作業のURLから画像を取得するが、私は私のウェブページのURLから複数の画像を読み込むことができますので、それを作成する方法について混乱しました。誰かが私を文字列に描画可能に変更通知ではなく、必ずここにこれを行うにはどのように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;
}
}
}
解決
あなたから引き、その後、あなたが持っている同じコードを使用しますが、配列またはリストの長さにわたってループに入れたいURLの配列またはリストを作成します。あなたがANRを生成しないように、そして、あなたは別のスレッドでこれを行う必要があります。 AsyncTaskを見上げます。
List<String> urls;
for(int i=0; i<urls.size(); i++) {
Drawable d = LoadImageFromWebOperations(urls.get(i));
// do something interesting
}
所属していません StackOverflow