开发者

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 );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜