Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get this behavior down is tricky, and took me quite a while to perfect. The meat of the problem is that the scroll listeners by themselves are not really quite sufficient to detect a "scroll stop" (including the directional buttons/trackball), as far as I could tell. I ended up doing a combination of things that works right as I expect it. </p> <p>The best way I figured I could do it was to extend ListView and override a few methods:</p> <pre><code> .... @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_UP) { startWait(); } return super.onKeyUp(keyCode, event); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { stopWait(); } if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { startWait(); } return super.onTouchEvent(event); } private OnScrollListener customScrollListener = new OnScrollListener() { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { stopWait(); } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) { startWait(); } else { stopWait(); } } }; //All this waiting could be improved, but that's the idea private Thread waitThread = null; private int waitCount = Integer.MIN_VALUE; public void stopWait() { waitCount = Integer.MIN_VALUE; } public synchronized void startWait() { waitCount = 0; if (waitThread != null) { return; } waitThread = new Thread(new Runnable() { @Override public void run() { try { for (; waitCount.get() &lt; 10; waitCount++) { Thread.sleep(50); } //Kick it back to the UI thread. view.post(theRunnableWithYourOnScrollStopCode); // HERE IS WHERE YOU DO WHATEVER YOU WANTED TO DO ON STOP } catch (InterruptedException e) { } finally { waitThread = null; } } }); waitThread.start(); } </code></pre> <p>Note that you also have to bind the <code>customScrollListener</code> in your constructors. This implementation is nice, I think, because it won't immediately fire the "event", it will wait a bit until it has actually fully stopped scrolling. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload