Ben
Ben

Reputation: 1849

Button click to use RecyclerView Adapter position

I have created a RecyclerView adapter which looks as following:

enter image description here

I have added to the Adapter an onClick which works when each row is clicked.

holder.itemView.setOnClickListener( new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(mView.getContext(), "person + " + position, Toast.LENGTH_LONG).show();
    }
} );

However, the only button that I really need is the "chat" Imagebutton. I had like that only when the user clicks on the chat button it will know which row of the adapter was clicked and based on it will create activity.

Is there a way for me to implement the adapter onClick call when I actually click on the button? Or more specifically, is there a way I can pass to chatButton.onClick the position of the row where it is placed?

Because I dont want the whole row to be clickable, only the chat button.

Thank you

Upvotes: 0

Views: 89

Answers (1)

Md. Asaduzzaman
Md. Asaduzzaman

Reputation: 15433

use like this:

holder.itemView.chatView.setOnClickListener( new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(mView.getContext(), "person + " + position, Toast.LENGTH_LONG).show();
    }
} );

Upvotes: 1

Related Questions