Question: Handling clicks in RecyclerView Adapter
See original GitHub issueHello,
I was wondering How can I handle clicks from a view inside a RecyclerView Adapter and later collect them outside this adapter for instance in a Fragment/Activity? I’m probably looking for something like PublishSubject
in RxJava
For instance
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DiscoverHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.section_title, parent, false)
view.clicks().collect() //How can I somehow propagate those clicks to a property?
..............
}
I used to do this with callbacks but I want to achieve a similar thing using this library.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
RecyclerView Item Click Listener the Right Way - Stack Overflow
A better way to handle clicks in ViewHolder . See the below example. class Holder extends RecyclerView.ViewHolder implements View.
Read more >RecyclerView Item Click Listener Best Practice - YouTube
Hello World, today we will take a quick look at what I consider to be the best practice when handling setting OnClickListener for...
Read more >The Modern Approach to handle Item Click on Recyclerview
The better approach is to set a click listener in onCreateViewHolder which invokes only once when a ViewHolder gets created. Now the question...
Read more >Android nested RecyclerView handling clicks, using OOP
I wanted to know when a user clicks on any View used in the Nested RecyclerView. For example, if the user clicks on...
Read more >Handling RecyclerView Clicks the Right Way using Kotlin
In this step, we will create our Adapter class that will do all the click operations. First, we create a class called OnClickListener...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh now I remember
Subject
is both aSubscriber
and anObservableSource
😃You can implement a similar API with Flow with an extension function:
Only saved a few characters though:)
The equivalence of RxJava
Subject
in Coroutines is Channel.You could use a
Channel
in your adapter to collect theview.clicks()
Flows emitted by each item, and expose it as a singleitemClicks: Flow<MyItem>
for Fragment / Activity to consume:In Activity / Fragment: