我有图像,我希望他们在画廊中使用适配器选择每个,它将使用画布绘制,我看了很多教程,我制作了我的代码,现在我不知道哪里错了我正在制作
Gallery g;
ImageAdapter imageAdapter;
Gallery g = (Gallery) findViewById(R.id.gBitmap);
imageAdapter = new ImageAdapter(this);
g.setAdapter(imageAdapter);
//selected Bitmap from gallery
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View v, int position, long id) {
applyBitmap(position);
}
});
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.first,
R.drawable.second,
R.drawable.fifth,
R.drawable.third,
R.drawable.fourth,
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position,
View convertView, ViewGroup parent) {
return iv;
}
}
public static void Bitmap(int position) {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inScaled = true;
opt.inPurgeable = true;
opt.inInputShareable = true;
Bitmap brightBitmap = BitmapFactory.decodeResource(null, position, opt);
iv.setImageBitmap(brightBitmap);
}
我需要让选定的mImageIds
使用名为Bitmap
答案 0 :(得分:1)
我不知道这对你有用,
但是在代码中进行一些更改,
<强> 1。 applyFrame(int position)
此代码行应为
Bitmap brightBitmap = BitmapFactory.decodeResource(getResources(), position, opt);
<强> 2。在getView()
中public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
第3。 setOnItemClickListener()
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View v, int position, long id) {
applyFrame(mImageIds[position]);
}
});
尝试这个,让我知道发生了什么......如果它有效,那么我会解释你。如何??
答案 1 :(得分:0)
您应该观看“the world of listView”视频,并知道如何为adapterView创建适配器(图库扩展它)。