smooth Scroll ListView To Top - Android android.widget

Android examples for android.widget:ListView

Description

smooth Scroll ListView To Top

Demo Code

import android.os.Build.VERSION;
import android.widget.ListView;

public class Main {

  public static void smoothScrollListViewToTop(final ListView listView) {
    if (listView == null) {
      return;/*w w w.ja  v a  2  s.c  o m*/
    }
    smoothScrollListView(listView, 0);
    listView.postDelayed(new Runnable() {

      @Override
      public void run() {
        listView.setSelection(0);
      }
    }, 200);
  }

  public static void smoothScrollListView(ListView listView, int position) {
    if (VERSION.SDK_INT > 7) {
      listView.smoothScrollToPositionFromTop(0, 0);
    } else {
      listView.setSelection(position);
    }
  }

}

Related Tutorials