I have a Multi-Selection RecyclerView. I am tring to handle button click inside to RecyclerView Item when It's selected/activated. But when an item selected/activated in RecyclerView I am not able to click the ChildView (Button) It handles RootView of content and reverts to the deactivated/notselected state.
I read the documantation It says
Selection Hotspot
This is an optional feature identifying an area within a view that is single-tap to select. Ordinarily a single tap on an item when there is no existing selection will result in that item being activated. If the tap occurs within the "selection hotspot" the item will instead be selected.
See OnItemActivatedListener for details on handling item activation.
I tried to override inSelectionHotspot function
/**
* Areas are often included in a view that behave similar to checkboxes, such
* as the icon to the left of an email message. "selection
* hotspot" provides a mechanism to identify such regions, and for the
* library to directly translate taps in these regions into a change
* in selection state.
*
* @return true if the event is in an area of the item that should be
* directly interpreted as a user wishing to select the item. This
* is useful for checkboxes and other UI affordances focused on enabling
* selection.
*/
public boolean inSelectionHotspot(@NonNull MotionEvent e) {
return false;
}
The document's comment reffers to Gmail application, that example to selection by clicking e-mail's leftside ImageView and you can able to move e-mail's content by clicking to Title or Description area. That's exactly what I'm trying to do.
ItemDetailsLookup.ItemDetails Class
class PurchaseItemDetails(var binding: ListObjectLevelPurchaseBinding) : ItemDetailsLookup.ItemDetails<LevelModel>() {
var itemPosition: Int = 0
lateinit var item: LevelModel
override fun getSelectionKey(): LevelModel? {
return item
}
override fun getPosition(): Int {
return itemPosition
}
override fun inSelectionHotspot(e: MotionEvent): Boolean {
val locationOnScreen = IntArray(2)
binding.buttonLevelPurchaseInspect.getLocationOnScreen(locationOnScreen)
val (left) = locationOnScreen
val right = left + binding.buttonLevelPurchaseInspect.width
Log.e("InSelectionHotspot","${e.x.roundToInt() !in left..right}")
return e.x.roundToInt() !in left..right
}
}
I also tried to override onItemActivatedListener nothing changed.
tracker = SelectionTracker.Builder<LevelModel>(
"selection.levels",
binding.recyclerviewBundleDetailPurchaseLevels,
PurchaseItemKeyProvider(adapter.currentList),
PurchaseItemLookup(binding.recyclerviewBundleDetailPurchaseLevels),
StorageStrategy.createParcelableStorage(LevelModel::class.java)
).withSelectionPredicate(
SelectionPredicates.createSelectAnything()
).build()