0
public class ImageAdapter extends BaseAdapter {
    LayoutInflater inflater;
    ImageView photo;
    CheckBox CHECK;
    BitmapFactory.Options options;

    public ImageAdapter(Context c) {
        inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    public int getCount() {
        return receivedphoto.size();
    }
    public Object getItem(int position) {
        return receivedphoto.get(position);
    }
    public long getItemId(int position) {
        return position;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null)  {
            convertView = inflater.inflate(R.layout.phototab_list, parent, false);
            photo = (ImageView)convertView.findViewById(R.id.PHOTOS);
            CHECK = (CheckBox)convertView.findViewById(R.id.PHOTOSCHECK);
            options = new BitmapFactory.Options();
            options.inSampleSize = 16;
        }
        Log.i("LOAD", position + "");
        if(ReceivePhotos.get(position) == null)  {
            ReceivePhotos.set(position, BitmapFactory.decodeFile((String)(receivedphoto.get(position)), options));
        }   
        photo.setImageBitmap(ReceivePhotos.get(position));
        int check = Photoischeck.get(position);
        if(check == 0)  {
            CHECK.setChecked(false);
        } else {
            CHECK.setChecked(true);
        }
        return convertView;
    }
}

我使用 ArrayList 作为 GridView 数据。但是当我向下滚动和向上滚动时,我的照片是混合的。混合意味着照片的位置发生了变化。这是为什么?请帮帮我ㅠㅜ

4

1 回答 1

0

试试这个...使用视图持有人来保存详细信息...

public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        final ViewHolder holder;
        if(convertView == null)  {
            view = inflater.inflate(R.layout.phototab_list, parent, false);
            holder = new ViewHolder();
            holder.photo = (ImageView)convertView.findViewById(R.id.PHOTOS);
            holder.CHECK = (CheckBox)convertView.findViewById(R.id.PHOTOSCHECK);
            holder.options = new BitmapFactory.Options();
            holder.options.inSampleSize = 16;
        }else {
     holder = (ViewHolder) view.getTag();
}
        Log.i("LOAD", position + "");
        if(ReceivePhotos.get(position) == null)  {
            ReceivePhotos.set(position, BitmapFactory.decodeFile((String)(receivedphoto.get(position)), options));
        }   
        holder.photo.setImageBitmap(ReceivePhotos.get(position));
        int check = Photoischeck.get(position);
        if(check == 0)  {
            holder.CHECK.setChecked(false);
        } else {
            holder.CHECK.setChecked(true);
        }
        return view;
    }
于 2013-08-28T15:18:59.020 回答