我在android中开发了一种图库应用程序,我希望显示从GridView.
中选择的图像
我从设备的SD卡获取图像,我使用CustomAdapter
来选择图像。
这是我的CustomGridAdapter.java
private class CustomGridAdapter extends BaseAdapter {
String[] items;
MainActivity context;
LayoutInflater inflater;
public CustomGridAdapter(MainActivity context, String[] items) {
this.context = context;
this.items = items;
inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return items.length;
}
@Override
public Object getItem(int position) {
return items[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.cell, null);
}
final ImageView img = (ImageView) convertView.findViewById(R.id.img);
Bitmap bmp = BitmapFactory.decodeFile(path + "/" + items[position] + "/off.png");
img.setImageBitmap(bmp);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
context.itemClicked(position);
}
});
return convertView;
}
}
有人可以帮忙吗?