列出拍摄Android的照片

时间:2014-04-22 12:47:05

标签: android android-listview

我试图在拍照后制作照片列表。拍摄secont照片后,它将显示为列表中的第二项。我遇到了一些问题。我已经创建了Adapters并尝试使用它。当我拍照时,同样的照片显示在列表视图中。我正在使用我在互联网上找到的方法。

照片类:

public class Photo {
    public Bitmap icon;
    public String title;
    public Photo(){
        super();
    }

    public Photo(Bitmap bitmap, String title) {
        super();
        this.icon = bitmap;
        this.title = title;
    }

}


public class PhotoAdapter extends ArrayAdapter<Photo> {

    Context context;
    int layoutResourceId;
    ArrayList<Photo> data = null;
    public PhotoAdapter(Context context, int layoutResourceId, ArrayList<Photo> data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        PhotoHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new PhotoHolder();
            holder.imgIcon = (ImageView) row.findViewById(R.id.imgIcon);
            holder.txtTitle = (TextView) row.findViewById(R.id.txtTitle);
            holder.del_but = (ImageView) row.findViewById(R.id.imgDel);

            row.setTag(holder);
        } else {
            holder = (PhotoHolder) row.getTag();
        }

        Photo photo = data.get(position) ;
        holder.txtTitle.setText(photo.title);
        holder.imgIcon.setImageBitmap(photo.icon);

        return row;
    }
}

照片持有人类:

static class PhotoHolder {
            ImageView imgIcon;
            TextView txtTitle;
            ImageView del_but;
        }

onCrete方法中的代码:

ArrayList<Photo> photo_data = new ArrayList<Photo>();

        adapter = new PhotoAdapter(this, R.layout.photos_list_item, photo_data);

        listView1 = (ListView) findViewById(R.id.listView1);
        listView1.setAdapter(adapter);

照片拍摄后开始的方法;

   private void setPic() {

        int targetW = 220;
        int targetH = 300;
        // Get the dimensions of the bitmap
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        bmOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        int photoW = bmOptions.outWidth;
        int photoH = bmOptions.outHeight;
        /* Figure out which way needs to be reduced less */
        int scaleFactor = 1;
        if ((targetW > 0) || (targetH > 0)) {
            scaleFactor = Math.min(photoW / targetW, photoH / targetH);
        }
        // Decode the image file into a Bitmap sized to fill the View
        bmOptions.inJustDecodeBounds = false;
        bmOptions.inSampleSize = scaleFactor;
        bmOptions.inPurgeable = true;

        Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        System.out.println("bitmap    " + bitmap);

        Photo li = new Photo(bitmap, "haha");
        adapter.addAll(li);
    }

我也想出了一个问题。我如何从listview获取图像? 我真的不明白getView是如何工作的

0 个答案:

没有答案