E
E
Eugene2017-04-03 15:29:08
Java
Eugene, 2017-04-03 15:29:08

RecyclerView Items?

There is a RecycleView in which I programmatically place a CardView. CardView consists of TextView and Button. It is necessary to programmatically understand which Button was clicked on and receive the text from this button. I read in onBindViewHolder that you can set your own onclicklistener for each button when building a RecycleView, but then how to get elements that should be changed when clicked (if they are in a neighboring running fragment) using the findviewbyid method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2017-04-03
@zagayevskiy

Your abstractions have flowed. In short, yes, you can put a listener in onBindViewHolder. Only this listener should pull another listener, your custom one. like interface MyAwesomeClickListener
{ voidOnClick(...); }
When you create an adapter, push the implementation of this interface to it. And that's it, in the implementation, do what you want.
PS getting text from this button is a bad idea. The button should only display the text, you don't need to read it from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question