1


I'm looking for a method to be fired when a programmatically scrolling (by using smoothscrolltoposition) has reached the given position.
I have an activity, with a listview. When the user taps a button, the list scrolls to a given position. I need to change the item layout properties of that position. I'm using a scroll listener, and overriding the onScroll method to do this, but the method is not executed at the end as the documentation says.
BTW: I'm using API 8.

Here my code:

public void scrollToPosition(View view) {
    this.myList.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // Here I need to be positioned in the right place, to change the row layout.
            MyActivity.this.myList.setOnScrollListener(null);
        }
    });
    this.myList.smoothScrollToPosition(this.position - 1);
}

TIA,
Milton.

manlio
  • 18,345
  • 14
  • 76
  • 126
Milton
  • 928
  • 1
  • 10
  • 22
  • Wow... looks like no body knows how to do that :( A comment with unsuccessful tries will be helpful too ! – Milton Jun 20 '13 at 12:21

1 Answers1

0

the problem of "smoothScrollToPosition" it scrolls the given position visible on the screen, not to the top of the screen. You need to determine whether you're scrolling down to your position or scrolling up to your position. that's first point, 2nd WHY are you removing the scroll listener just when it started scrolling? "onScroll" is called when the listview just now started scrolling. You need to check onScrollStateChanged, it has 3 states, touchScroll -> user is touching the listview and scrolling, flingScroll ->listview is scrolling but user isnt touching it, and scrollIdle -> user isnt touching anything and the scroll view is still

your question does not exactly specify what EXACTLY you need to do, please edit it and i will help you

Lena Bru
  • 13,521
  • 11
  • 61
  • 126