0

I have a ListActivity that displays two pieces of information in each line of the list (one image sett in an ImageView and a text description set in a TextView). These information I get through a XML file from a download. Every thing works fine!!!!! :-).

On OnListItemClick, I would like to get the Bitmap from the ImageView that the user selected.

To get an image from an ImageView, I use this :

ImageView img = (ImageView) l.findViewById(R.id.imageViewXYZ);
img.buildDrawingCache();
Bitmap b = img.getDrawingCache();

But inside the onClick event of the ListActivity, how can I get the this bitmap?

4

1 回答 1

3
yourListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> adapterView, final View view, final int position, final long id) {
            final ImageView imageView = (ImageView) view.findViewById(R.id.imageViewXYZ);
            final BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
            final Bitmap yourBitmap = bitmapDrawable.getBitmap();
        }
    });

代码假定,您在 ListViews ImageView 项目中设置了一个位图setImageBitmap(强制转换为 BitmapDrawable)

于 2012-07-03T15:15:40.963 回答