RecyclerView: Nested clickable views - android

I have RecyclerView which has 2 Buttons inside its item and also swipable ViewPager. I need to set onClickListener for entire RecyclerView item but also allow to interact with ViewPager by swiping and those 2 Buttons.
Is this possible. I tried everything. Tried to set every single View to clickable false. Only Buttons and RecyclerView item parent is clickable. Also added to parent view android:descendantFocusability="afterDescendants" but none of this worked.
ViewPager is not clickable only swipable.

I couldn't solve this issue normally, but I solved it by little hack, I set onClickListener for each page of ViewPager and sent onClick function as parameter from RecyclerView item. This way clicking on page of the ViewPager will do the same as root in onBindViewHolder for its parent.
onClick listener is set inside custom ViewPagerAdapter right before I return layout to ViewPager in instantiateItem() function.
If I wanted to achieve onClick for entire item, I will probably never wanted to click on ViewPager item to perform other action. It would be bad design. Swiping ViewPager inside RecyclerView is not triggering onClick event so its fine.

Related

Android RecyclerView's parent onClick

I have a CardView that has some children and also a RecyclerView with android:layout_height="wrap_content". I have onClickListener on this CardView and it works fine until I click on the RecyclerView. Only CheckBoxes in its items need to be clickable. Could you please tell me how I make it works? Preferably in Kotlin
Here is a representing image of my layout:

Scroll inside RecyclerView item

I have a vertical RecyclerView and inside every item a custom view with own horizontal scroll and scale. When I try to scroll view inside item I get scroll conflict RecyclerView interrupts touch event and tries to move the list.
How can I restrict RecyclerView to handle horizontal swipe event?
I tried to interrupt event via RecyclerView.OnItemTouchListener and pass them directly to my custom view. That almost works but sometimes I get wrong events and scroll in the custom view does not work.
Has someone else faced this problem?
Try use simple OnTouchListener instead OnItemTouchListener

ViewPager items in a ListView not clickable

I have a ListView where each item contains a ViewPager (in a CardView, not sure if that matters). The desired behavior is that:
Clicks on the items work normally, as if the items were simple TextViews for example.
Swiping in the ViewPager works.
Right now, clicks on the ViewPager don't work. Clicking outside of the ViewPager does work as expected however, I had to set focusable="true" and focusableInTouchMode="true" for this to work. Other than that, there's nothing unusual in the code.

ViewPager in ListView items

I implemented ViewPager in ListView items. In general works perfect, but have some issue.
When I scroll ListView and then touch on screen (during scrolling list) in this case I can't scroll ViewPager in this item, ListView has focus. I should select it again for ability to swipe. ListView has returned SCROLL_STATE_TOUCH_SCROLL state, when I touch it during the scroll. At this moment I should focused on ViewPager for ability to swipe items.
Can I solve this issue without any scroll conflicts in ListView and ViewPager? I guess that it's imposible, but, decided to ask here.
Or, maybe you can advice me to use some other control to implementing swipe in ListView items. But scroll animation should be the same as on ViewPager.
Thanks for any advice.
Depending on your XML, you end up with needing to implement OnTouchListener. If the view you want to handle the event can handle it, then return true, if not false. Then the parent can handle it. You might also want to look at ViewGroups, particularly the onInterceptTouchEvent.

ViewPager and longclick

I have a layout that is over top of a viewpager.
The viewpager is functioning as a dynamically changing background.
Upon a long click of the viewpager (long clicking the background), the foreground elements should disappear.
I put a long click listener on the viewpager, but it doesn't respond to this out of the box. This linked answer seems to touch on the subject, but I'm not sure how to implement it, help?
https://stackoverflow.com/a/11303508/727429
I'm also experimenting with other UX (clicks vs buttons vs motion gestures to do the same thing) but for now I want to solve this problem
The answer is to set a listener inside the viewpager's instantiateItem class.
Basically declare your View within that, and set an onClickListener on that

Categories

Resources