Java Code Examples for android.widget.ListView#postDelayed()

The following examples show how to use android.widget.ListView#postDelayed() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void show(final int selected) {
    if (listAdapter == null) {
        return;
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    dialog = builder.setSingleChoiceItems(listAdapter, 0, this).create();
    dialog.setCanceledOnTouchOutside(true);
    final ListView listView = dialog.getListView();
    listView.setFastScrollEnabled(true);
    listView.setScrollbarFadingEnabled(false);
    listView.postDelayed(new Runnable() {
        @Override
        public void run() {
            listView.setSelection(selected);
        }
    }, DELAY_MILLIS);
    dialog.show();
}
 
Example 2
Source Project: COCOQuery   File: AbstractViewQuery.java    License: Apache License 2.0 6 votes vote down vote up
public T smoothScrollTo(final int position) {
    if (view instanceof ListView) {
        final ListView listView = (ListView) view;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            listView.smoothScrollToPositionFromTop(position, 0);
            listView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    // Mock touchEvent to stop listView Scrolling.
                    listView.onTouchEvent(MotionEvent.obtain(System.currentTimeMillis(),
                            System.currentTimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0));
                }
            }, 150 - 20);

            listView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    listView.setSelectionFromTop(position, 0);
                }
            }, 150);
        } else {
            listView.setSelectionFromTop(position, 0);
        }
    }
    return self();
}
 
Example 3
Source Project: Qshp   File: ListViewUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 滚动列表到顶端
 *
 * @param listView
 */
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);
}