我在xml文件中使用图像视图和图库。我正在获取webservice(远程图像)的图库图像。
当我从库中选择图像时,我想在android图像视图中显示。
这是我的代码,
ImageAdapter.java
public class ImageAdapter extends BaseAdapter
{
private Context context = null;
DataService Ds;
LayoutInflater mInflater;
private String[] myRemoteImages;
public ImageAdapter(Context context)
{
this.context = context;
//myRemoteImages = imgArray;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return this.myRemoteImages.length;
}
@Override
public final Object getItem(int position)
{
return position;
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View view, ViewGroup group)
{
ImageView imageView = new ImageView(this.context);
try {
URL aURL = new URL(myRemoteImages[position]);
System.err.println(aURL);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
imageView.setImageBitmap(bm);
} catch (IOException e) {
//imageView.setImageResource(R.drawable.nopic);
Log.e("DEBUGTAG", "Remote Image Exception", e);
}
imageView.setImageResource(position);
imageView.setLayoutParams(new Gallery.LayoutParams(105, 70));
return imageView;
}
public String[] getMyRemoteImages() {
return myRemoteImages;
}
public void setMyRemoteImages(String[] myRemoteImages) {
this.myRemoteImages = myRemoteImages;
}
}
and DisplayImage.java
ImageView imgView;
gallery = (Gallery) this.findViewById(R.id.Gallery01);
imageAdapter = new ImageAdapter(this);
imageAdapter.setMyRemoteImages(ItemList.getImages());
gallery.setAdapter(imageAdapter);
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent,
View v, int position, long id)
{
System.out.println("gallery position" +imageAdapter.getItemViewType(position));
imgView.setImageResource(imageAdapter.getItemViewType(position));
}
});
}
任何人都可以帮助我?
提前致谢
答案 0 :(得分:0)
现在它的工作。这是我的代码,
DisplayImage.java:
ImageView imgView;
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
System.out.println("Gallery position :"
+ bikeItemList.getOriginalImages().get(position));
UrlImageViewHelper.setUrlDrawable(imgView, bikeItemList
.getOriginalImages().get(position));
}
});