lfaa
lfaa

Reputation: 13

get the Bitmap from ImageView in a ListView

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?

Upvotes: 0

Views: 4063

Answers (1)

Alex Orlov
Alex Orlov

Reputation: 18107

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();
        }
    });

Code assumes, that you have a bitmap set in ListViews ImageView item through setImageBitmap (cast to BitmapDrawable)

Upvotes: 3

Related Questions