0

I try to know when the user is scrolling over the end of the screen.

My layout is ScrollView.

I create new costume ScrollView object to override onScrollChanged using to code here:

Detect end of ScrollView

My code for knowing when the user scrolls to the end of the screen is:

I create view in my layout below my scrollview called checkEndOfList.

In my code i try to check the end of the list if is shown.

My XML:

 <com.example.workoutlog.WallScrollView
        android:id="@+id/wallList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll" >

        <LinearLayout
            android:id="@+id/workoutsWall"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
        </LinearLayout>
    </com.example.workoutlog.WallScrollView>

    <LinearLayout
        android:id="@+id/checkEndOfList"
        android:layout_width="fill_parent"
        android:layout_height="0.1sp"
        android:layout_below="@+id/wallList"
        android:orientation="horizontal"
        android:background="@color/transparent" >
    </LinearLayout>

This is my java code for checking is the user scrolls over the end of the page:

@Override
        public void onScrollChanged(WallScrollView scrollView, int x,
                int y, int oldx, int oldy) {
            // TODO Auto-generated method stub          
            if(y - oldy == 0 && checkEndOfList.isShown() && y != 0 && oldy != 0)
            {
//MY CODE
}

The code i tried doest work for me. I get call for end of screen even when i didnt scrolled over the screen.

Thank for helping.

Community
  • 1
  • 1
dasdasd
  • 2,443
  • 10
  • 41
  • 67

1 Answers1

0

you can use this way:

    private int visibleThreshold = 5;
    private int currentPage = 0;
    private int previousTotal = 0;
    private boolean loading = true;

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {
        if (loading) {
            if (totalItemCount > previousTotal) {
                loading = false;
                previousTotal = totalItemCount;
                currentPage++;
            }
        }
        if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
            // I load the next page of gigs using a background task,
            // but you can call any function here.
            new LoadGigsTask().execute(currentPage + 1);
            loading = true;
        }
    }
Shani Goriwal
  • 2,303
  • 1
  • 13
  • 31