Code example for ListView

Methods: setSelection, postDelayed

0
    public static void smoothScrollListViewToTop(final ListView listView) {
        if (listView == null) {
            return; 
        } 
        smoothScrollListView(listView, 0);
        listView.postDelayed(new Runnable() {
 
            @Override 
            public void run() { 
                listView.setSelection(0);
            } 
        }, 200); 
    } 
 
    /** 
     * 滚动列表到position 
     *  
     * @param listView 
     * @param position 
     * @param offset 
     * @param duration 
     */ 
    public static void smoothScrollListView(ListView listView, int position) {
        if (VERSION.SDK_INT > 7) {
            listView.smoothScrollToPositionFromTop(0, 0);
        } else { 
            listView.setSelection(position);
        } 
    } 
}