ウェブサイトからギャラリーに画像を読み込もうとしています。画像をギャラリーに読み込めません。最初の(メイン)画像が読み込まれます。
public class viewimages extends Activity {
private Gallery gallery;
private ImageView imgView;
private Integer[] Imgid = {
R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewimages);
try {
URL url = new URL("http://www.mysite.com/images/1000298/pics/1.jpg");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection()
.getInputStream());
imgView = (ImageView)findViewById(R.id.ImageView01);
imgView.setImageBitmap(bmp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
gallery = (Gallery) findViewById(R.id.examplegallery);
gallery.setAdapter(new AddImgAdp(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
imgView.setImageResource(Imgid[position]);
}
});
}
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
typArray.recycle();
}
public int getCount() {
return Imgid.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgView = new ImageView(cont);
List<String> imageNames = new ArrayList<String>();
imageNames.add("1.jpg");
imageNames.add("2.jpg");
//etc. until you've added all images
for (int i = 0; i < imageNames.size(); i++){
URL url;
try {
url = new URL("http://www.mysite.com/images/1000298/pics/" + imageNames.get(i));
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection()
.getInputStream());
imgView.setImageBitmap(bmp);
imgView.setLayoutParams(new Gallery.LayoutParams(80, 70));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(GalItemBg);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return imgView;
}
}
}
問題は、AddImgAdpクラスのgetView()にあるようです。これがウェブサイトから画像を読み込もうとする正しい場所かどうかわかりませんか?