How to select middle element in listview in android onscroll?
How can I select the middle element in a listview on scroll stop? Suppose I have six elements and I am rotating it circularly. On stop of onscroll, I want to select the middle part on that listview. How can I do this?
@Override
public void onScroll(AbsListView view,
开发者_如何转开发 int firstVisibleItem,
int visibleItemCount,
int totalItemCount) {
this.firstVisibleItem = firstVisibleItem;
Rect r = new Rect();
}
Try calculating the positon of the middle and then use setSelection( int position )
to set the selection.
@Override
public void onScroll(AbsListView view,
int firstVisibleItem,
int visibleItemCount,
int totalItemCount) {
view.setSelection( visibleItemCount / 2 );
}
精彩评论