Lucas Storti
Lucas Storti

Reputation: 88

Android ListView Get Bitmap from child

I am creating a custom List View, that its items are as it follows, as you can see I have a cardView and a ImageView inside that cardView:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="fill_parent"
    android:layout_height="280dp"
    android:layout_marginTop="32dp"
    android:background="@color/button_material_light"
    android:foreground="?android:attr/selectableItemBackground"
    card_view:cardBackgroundColor="#ffffff"
    card_view:cardCornerRadius="2dp"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false">

        <ImageView
            android:id="@+id/suggestionImageView"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:scaleType="centerCrop"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"/>

        <TextView
            android:id="@+id/suggestionTextView"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/suggestionImageView"
            android:padding="10dp"
            tools:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"I/>
    </RelativeLayout>

</android.support.v7.widget.CardView>

And I would like to get the BitMap from that imageView on the Item that was clicked:

mSuggestionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //code to get Bitmap from suggestionImageView here
        }
    });

Any idea on how to do that friends?

Upvotes: 0

Views: 177

Answers (1)

younes zeboudj
younes zeboudj

Reputation: 924

mSuggestionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ImageView img= (ImageView)view.findViewById(R.id.suggestionImageView);
        Bitmap bitmap=((BitmapDrawable)img.getDrawable()).getBitmap();
        //bitmap ....
    }
});

Upvotes: 2

Related Questions