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

The following examples show how to use android.widget.ListView#postDelayed() . 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
Source File: CountryListSpinner.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
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 File: AbstractViewQuery.java    From COCOQuery with 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 File: ListViewUtils.java    From Qshp with 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);
}