如何在滚动列表项时禁用列表视图触摸或单击。 我在按钮点击事件上做listview滚动,我需要listview 滚动时单击禁用。 我想将listview设置为wheel-view
答案 0 :(得分:1)
使用setOnScrollListener
listview.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_IDLE) {
isScrolling = false;
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
isScrolling = true;
}
});
并在setOnItemClickListener
执行该操作:
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(!isScrolling){
//do your code
}
}
});
答案 1 :(得分:0)
在listview上设置OnScrollListener,如下所示
setOnScrollListener(new OnScrollListener() {
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
Log.i("a", "scrolling stopped...");
//attach the click listerner here
} else if(scrollState==OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
//remove the click listener here
}
});