Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select ReyclerView item(just single tap) with recycler view selection library

I new to RecyclerView Selection library. I prepared RecyclerView to select multiple item just single tap. My problem is that all of the article and tutorial show that selection process start with long press.

How can i overwrite to start selection with single tap? Thanks.

I'm using implementation 'androidx.recyclerview:recyclerview-selection:1.0.0'

The tutorial,I tried..

  • https://github.com/guenodz/recyclerview-selection-demo
  • https://medium.com/@Dalvin/android-recycler-view-with-multiple-item-selections-b2af90eb5825
  • http://androidkt.com/recyclerview-selection-28-0-0/
  • https://code.tutsplus.com/tutorials/how-to-add-selection-support-to-a-recyclerview--cms-32175
like image 712
amlwin Avatar asked Mar 12 '19 09:03

amlwin


People also ask

How do I select a single item in RecyclerView?

For single selection, we just need to hold the position that clicked in the recyclerview. When user clicks the another position, forget previous one and make new position as hold position.

What is RecyclerView selection?

Pretty much every single app has a list of something they want to display. RecyclerView Selection is a library that will allow you to handle item selection a lot easier. It will help you handle motion events and touch events, and convert them into selection in the RecyclerView.


1 Answers

After digging over weeks, I found working solution. According to 한로니

If you want single-tap to select, just override inSelectionHotspot(e: MotionEvent) to return true

object : ItemDetailsLookup.ItemDetails<Long>() {
        override fun getSelectionKey(): Long? {

            return itemId
        }

        override fun getPosition(): Int {
            return adapterPosition
        }

        override fun inSelectionHotspot(e: MotionEvent): Boolean {
            return true
        }

For more u can see on Here

like image 99
amlwin Avatar answered Oct 11 '22 02:10

amlwin