Is there anyway i can detect a scroll and scroll stop events ?
This solved my problem ! :)
svMovieDetails.setOnTouchListener( new View.OnTouchListener( ) {
@Override
public boolean onTouch( View v, MotionEvent event ) {
switch ( event.getAction( ) ) {
case MotionEvent.ACTION_SCROLL:
case MotionEvent.ACTION_MOVE:
Log.e( "SCROLL", "ACTION_SCROLL" );
break;
case MotionEvent.ACTION_DOWN:
Log.e( "SCROLL", "ACTION_DOWN" );
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
Log.e( "SCROLL", "SCROLL_STOP" );
break;
}
return false;
}
} );
How to detect whether Android Scroll view is in idle state?
Find the solution
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch( View v, MotionEvent event ) {
switch ( event.getAction( ) ) {
case MotionEvent.ACTION_SCROLL:
case MotionEvent.ACTION_MOVE:
Log.e( "SCROLL", "ACTION_SCROLL" );
break;
case MotionEvent.ACTION_DOWN:
Log.e( "SCROLL", "ACTION_DOWN" );
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
Log.e( "SCROLL", "SCROLL_STOP" );
break;
}
return false;
}
});
Android Kotlin - detect / listen when NestedScrollView stops scrolling
Ok this is how I solved it:
private var countDownTimer: CountDownTimer? = null
private fun lastPosUpdate(memeID: Long, scrollPos: Int){
if(countDownTimer != null){
countDownTimer!!.cancel()
}
countDownTimer = object: CountDownTimer(300, 300) {
override fun onTick(millisUntilFinished: Long) {
}
override fun onFinish() {
Log.d(tagg, "scroll finished")
}
}
countDownTimer!!.start()
}
holder.scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
lastPosUpdate(meme.id, scrollY)
})
Android - How to Scroll to Begining or end of ScrollView after Scrolling Stopped?
Hi i built a solution using the link you provide here and another question(Android: How to scroll ScrollView in top.
Create a class named CustomScrollView :
public class CustomScrollView extends ScrollView {
private long lastScrollUpdate = -1;
public CustomScrollView(Context context) { super(context);}
public CustomScrollView(Context context, AttributeSet attrs) { super(context,attrs);}
public CustomScrollView (Context context, AttributeSet attrs, int default_style){super(context, attrs, default_style);}
private class ScrollStateHandler implements Runnable {
@Override
public void run() {
long currentTime = System.currentTimeMillis();
if ((currentTime - lastScrollUpdate) > 100) {
lastScrollUpdate = -1;
onScrollEnd();
} else {
postDelayed(this, 100);
}
}
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (lastScrollUpdate == -1) {
onScrollStart();
postDelayed(new ScrollStateHandler(), 100);
}
lastScrollUpdate = System.currentTimeMillis();
}
private void onScrollStart() {
// Feel Free to add something here
}
private void onScrollEnd() {
this.fullScroll(View.FOCUS_UP); // Each time user finish with scrolling it will scroll to top
}}
in your xml add:
<YOUR-PACKAGE-NAME.CustomScrollView
android:id="@+id/scrollMe"
android:layout_width="match_parent"
android:layout_height="100dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tEST\nSCROLL DOWN\n\n\n\nHello World!\n test \n test \nSCROLL\n"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</YOUR-PACKAGE-NAME.CustomScrollView>
Feel free to ask anything :)
Detect if a ScrollView is scrolling up or down - Android
you need to create a class that extends ScrollView
public class ExampleScrollView extends ScrollView
and then Override onScrollChanged
that gives you the old and new scroll positions and from there you can detect which direction
protected void onScrollChanged(int l, int t, int oldl, int oldt)
how to detect Android ListView Scrolling stopped?
Try using the setOnScrollListener and implement the onScrollStateChanged with scrollState == 0 ... do what you need to do...
setOnScrollListener(new OnScrollListener() {
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
Log.i("a", "scrolling stopped...");
}
}
});
How to detect if the scrollview stops scrolling in nativescript angular?
You could listen to the touch
event and make sure event.action
is TouchAction.up.
Edit: If you want to attach your own implementation of UIScrollViewDelegate
on iOS, you could do this. My version of delegate accepts the original delegate as a parameter, so I don't loose anything that is already implemented in the original delegate.
(<any>ScrollView.prototype).originalAttachNative = (<any>ScrollView.prototype).attachNative;
(<any>ScrollView.prototype).attachNative = function () {
this.originalAttachNative();
const newDelegate = MyUIScrollViewDelegateImpl.initWithOriginalDelegate(this._delegate);
this._delegate = newDelegate;
this.nativeViewProtected.delegate = newDelegate;
};
Related Topics
Android: Coloring Part of a String Using Textview.Settext()
Change Screen Orientation Programmatically Using a Button
Android - Set Max Length of Logcat Messages
How to Start Genymotion Device
How to Create PDFs in an Android App
Why Does Android Webview Sporadically Not Sending My Session Cookie
Adb Not Finding My Device/Phone (Macos X)
How to Return to a Parent Activity Correctly
How to Use Opencv in Using Gradle
How to Get Onclick Event on Webview in Android
How to Get Resource Name from Resource Id
Android Intent for Twitter Application
Android Multiple Email Attachments Using Intent
How to Check If My Edittext Fields Are Empty
Adding Local .Aar Files to Gradle Build Using "Flatdirs" Is Not Working