Java Code Examples for android.widget.AbsListView#setSelection()

The following examples show how to use android.widget.AbsListView#setSelection() . 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: CustomListFragment.java    From SmileEssence with MIT License 6 votes vote down vote up
protected void updateListViewWithNotice(AbsListView absListView, CustomListAdapter<?> adapter, boolean addedToTop) {
    int before = adapter.getCount();
    adapter.notifyDataSetChanged(); // synchronized call (not adapter#updateForce())
    int after = adapter.getCount();
    int increments = after - before;
    if (increments > 0) {
        adapter.setNotifiable(false);
        notifyListUpdated(increments);
        if (addedToTop) {
            absListView.setSelection(increments + 1);
            absListView.smoothScrollToPositionFromTop(increments, 0);
            absListView.setSelection(increments);
        } else {
            absListView.smoothScrollToPositionFromTop(before, 0);
        }

        if (increments == 1) {
            adapter.setNotifiable(true);
        }
    } else {
        adapter.setNotifiable(true);
    }
}
 
Example 2
Source File: ScrollUtils.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
/**
 * 滚动列表到position
 *
 * @param listView
 * @param position
 */
public static void smoothScrollListView(AbsListView listView, int position) {
    if (Build.VERSION.SDK_INT > 7) {
        listView.smoothScrollToPositionFromTop(0, 0);
    } else {
        listView.setSelection(position);
    }
}
 
Example 3
Source File: ListViewUtils.java    From FeedListViewDemo with MIT License 5 votes vote down vote up
/**
 * 滚动列表到position
 *
 * @param listView
 * @param position
 */
public static void smoothScrollListView(AbsListView listView, int position) {
    if (Build.VERSION.SDK_INT > 7) {
        listView.smoothScrollToPositionFromTop(0, 0);
    } else {
        listView.setSelection(position);
    }
}