开发者

How to select middle element in listview in android onscroll?

开发者 https://www.devze.com 2023-04-11 16:49 出处:网络
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. H

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

精彩评论

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

关注公众号