onClick method not working properly after NestedScrollView scrolled
It is a bug of the NestedScrollView, the detail of the bug can be found in here: issue. The problem is that mScroller.isFinished()
in onInterceptTouchEvent(MotionEvent ev)
will not return true
after a fling operation (even if the fling is stopped). Therefore the touch event is intercepted.
This bug have been reported for a while, but still have not been fixed. So I have created by own version of bug fix for this problem. I implemented my own NestedScrollView
, copied all the code from NestedScrollView
and having the with the following amendments:
public class NestedScrollView extends FrameLayout implements NestedScrollingParent, NestedScrollingChild {
...
private void initScrollView() {
...
// replace this line:
// mScroller = new ScrollerCompat(getContext(), null);
mScroller = ScrollerCompat.create(getContext(), null);
...
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
...
switch (action & MotionEventCompat.ACTION_MASK) {
...
case MotionEvent.ACTION_DOWN: {
...
// replace this line:
// mIsBeingDragged = !mScroller.isFinished();
mIsBeingDragged = false;
...
}
}
}
}
And this NestedScrollView
should have the same behaviour as the original one.
onClick method inside RecyclerView not working after NestedScrollView scrolled
Okey, I found the solution here, we need:
public class FixAppBarLayoutBehavior extends AppBarLayout.Behavior {
public FixAppBarLayoutBehavior() {
super();
}
public FixAppBarLayoutBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target,
int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,
dxUnconsumed, dyUnconsumed, type);
stopNestedScrollIfNeeded(dyUnconsumed, child, target, type);
}
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child,
View target, int dx, int dy, int[] consumed, int type) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
stopNestedScrollIfNeeded(dy, child, target, type);
}
private void stopNestedScrollIfNeeded(int dy, AppBarLayout child, View target, int type) {
if (type == ViewCompat.TYPE_NON_TOUCH) {
final int currOffset = getTopAndBottomOffset();
if ((dy < 0 && currOffset == 0)
|| (dy > 0 && currOffset == -child.getTotalScrollRange())) {
ViewCompat.stopNestedScroll(target, ViewCompat.TYPE_NON_TOUCH);
}
}
}
}
and, in our AppBarLayout:
<android.support.design.widget.AppBarLayout>
...
app:layout_behavior="your.package.FixAppBarLayoutBehavior"
...
</android.support.design.widget.AppBarLayout>
Items within NestedScrollView need to be clicked twice after scrolling to top or bottom
Apparently this is a bug:
https://code.google.com/p/android/issues/detail?id=178041
As of today, it's not fixed in the support library v23.
Clicklistener / Touchlistener on elements inside NestedScrollview do intercept scroll
It's a bug in the Android Support Library. See here: https://code.google.com/p/android/issues/detail?id=182549
Scrollview and OnClick handlers not working when view is cleared and re-created
I've managed to resolve the issue I was having. I tried what was suggested but unfortunately it didn't have a lot of effect.
What I had currently was one fragment, which had to linear layout containers, and when the view was switched one container was hidden and the container shown and then reload the relevant view content.
I've instead changed it so each view, is instead in a different fragment and with its own XML layout file, then when the view is switched, it uses a fragment transaction to replace one fragment view with the other and then uses the same code as I had above to dynamically populate the relevant view content.
RecyclerView onClick event is not working with SwipeRefreshLayout?
I had same problem not so long ago. I fixed mine by adding NestedScrollView as SwipeRefreshLayout child, and then simply put your recycler layout as NestedScrollView's child. See example below :
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/mahadevSwipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
// I didn't put mandatory constraints, but you'll have to
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/mahadevRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Alternatively, you could also keep your code like it is, and add custom scrolling behavior with scroll listener.
Tell me if my first guess don't work, i'll give you example of custom scroll handling.
Buttons inside fragments not firing first time in scroll view?
The issue is due to a bug in android support library NestedScrollView. It can be found here :
https://code.google.com/p/android/issues/detail?id=178041
This issue will most probably be fixed in next release. Till then you can see the workaround from this post :
onClick method not working properly after NestedScrollView scrolled
Related Topics
How to Get Current Process Name in Android
Adb Shell Su Works But Adb Root Does Not
Onoptionsitemselected Not Called When Using Actionlayout (Sherlockactionbar)
Android - Reduce Image File Size
Just Upgraded My Os X to Yosemite, Android Device Chooser Not Showing Device - What to Do
Session 'App': Error Installing APK
How to Use The Limit Argument in an Sqlite Query with Android
How to Check Database on Not Rooted Android Device
Multiple Notifications to The Same Activity
On Android, How to Switch Activities Programmatically
What Are Intent-Filters in Android
Is There a Maximum Size to Android Internal Storage Allocated for an App
Android Get Application's 'Home' Data Directory
How to Open The Avd Manager on Ubuntu Linux from The Command Line
How to Get The Application's Icon from The Package Name
Is There Another Place to Get a Google-Services.JSON
Difference Between Getview & Getdropdownview in Spinneradapter