When I am developing an Android application,how to set that a ListView can not scroll,but it can be clicked and long clicked,thank you
问问题
137 次
2 回答
0
To disable scrolling in ListView and keep it responding for clicking at the same time you need to override dispatchTouchEvent() method in your customListView as shown below:
@Override
public boolean dispatchTouchEvent(MotionEvent event){
if( event.getAction() == MotionEvent.ACTION_MOVE)
return true;
return super.dispatchTouchEvent(event);
}
or
listView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
return true;
}
return false;
}
});
于 2013-01-06T03:51:21.820 回答
0
If your list should not scroll use a ViewGroup like a LinearLayout
and add all the items to this ViewGroup in a loop in your code. If you want a whole row to be clickable you have to use another ViewGroup as the root node for each row and add the OnClickListener
and OnLongClickListener
to this View.
于 2013-01-07T17:33:46.577 回答