我正在尝试获取加载图像的位置,因此当我在 GridView 中单击它时,它会全屏显示。
问题是我不知道如何从我的适配器获取图像的位置!我需要设置 imageResurce ..imageView.setImageResource(MyAdapter.getItem(position));
这是错误的。我仍然找不到加载图像的位置...
我的适配器代码:
public class ImageAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public ArrayList<String> f = new ArrayList<String>();// list of file paths
File[] listFile;
Bitmap myBitmap;
int position;
public ImageAdapter(Context context) {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return f.size();
}
public Object getItem(int position) {
return f.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(
R.layout.galleryitem, null);
holder.imageview = (ImageView) convertView.findViewById(R.id.thumbImage);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
myBitmap = BitmapFactory.decodeFile(f.get(position));
holder.imageview.setImageBitmap(myBitmap);
return convertView;
}
public void getFromSdcard()
{
File file= new File(android.os.Environment.getExternalStorageDirectory(),"/InstaDownloader-");
if (file.isDirectory())
{
listFile = file.listFiles();
for (int i = 0; i < listFile.length; i++)
{
f.add(listFile[i].getAbsolutePath());
}
}
}
}
class ViewHolder {
ImageView imageview;
}