Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how I did it:</p> <p>I made an observable scroll view class.</p> <pre><code>public class ObservableScrollView extends ScrollView{ private ScrollViewListener scrollViewListener = null; public ObservableScrollView(Context context) { super(context); } public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public ObservableScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public void setScrollViewListener(ScrollViewListener scrollViewListener) { this.scrollViewListener = scrollViewListener; } @Override protected void onScrollChanged(int x, int y, int oldx, int oldy) { super.onScrollChanged(x, y, oldx, oldy); if(scrollViewListener != null) { scrollViewListener.onScrollChanged(this, x, y, oldx, oldy); } } </code></pre> <p>}</p> <p>I created a new interface called Scroll View Listener.</p> <pre><code>public interface ScrollViewListener { void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy); </code></pre> <p>}</p> <p>Then in the activity I implemented this interface.</p> <pre><code>public class MainActivity extends Activity implements ScrollViewListener { </code></pre> <p>Then it will force you to use the following method.</p> <pre><code>// scroll view listener. used to load new page if user scrolls to bottom @Override public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { View view = (View) scrollView .getChildAt(scrollView.getChildCount() - 1); int diff = (view.getBottom() - (scrollView.getHeight() + scrollView .getScrollY())); if (diff &lt;= DISTANCE_FROM_BOTTOM) { LOADNEXTTHINGS(); } } </code></pre> <p>The <code>DISTANCE_FROM_BOTTOM</code> is in pixels if I remember correctly.</p> <p>Keep in mind that <code>LOADNEXTTHINGS()</code> will be called if the user is changing the scroll position and in the range that is between <code>diff &lt;= DISTANCE_FROM_BOTTOM</code>. You should have a loading value to control this... like </p> <pre><code>if(diff &lt;= DISTANCE_FROM_BOTTOM &amp;&amp; !loadingNextThings){ loadingNextThings = true; LOADNEXTTHINGS(); } </code></pre> <p>then when you are done loading next things do <code>loadingNextThings = false;</code></p> <p>Personally, I prefer using FSMs.</p>
    singulars
    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. 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