smooth Scroll ListView To Top - Android User Interface

Android examples for User Interface:ListView

Description

smooth Scroll ListView To Top

Demo Code


//package com.java2s;

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

public class Main {

    public static void smoothScrollListViewToTop(final ListView listView) {
        if (listView == null) {
            return;
        }/*ww  w  .  j  av  a2  s .  com*/
        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