慕莱坞森
这是一个非常简化的版本,它使用两个侦听器(onTouch用于滑动检测,onClickIem用于项目单击检测)使用isSwipe标志停止onClickItemListener,直到其确认不是滑动在检测到点击不是第一次刷卡的情况下 listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { if(!isSwipe) { adapter.increase(arg2); adapter.notifyDataSetChanged(); } } });检测滑动 listView.setOnTouchListener(new OnTouchListener() { private int action_down_x = 0; private int action_up_x = 0; private int difference = 0; @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: action_down_x = (int) event.getX(); isSwipe=false; //until now break; case MotionEvent.ACTION_MOVE: if(!isSwipe) { action_up_x = (int) event.getX(); difference = action_down_x - action_up_x; if(Math.abs(difference)>50) { Log.d("action","action down x: "+action_down_x); Log.d("action","action up x: "+action_up_x); Log.d("action","difference: "+difference); //swipe left or right if(difference>0){ //swipe left Log.d("action","swipe left"); adapter.decrease(selectedItem); adapter.notifyDataSetChanged(); } else{ //swipe right Log.d("action","swipe right"); } isSwipe=true; } } break; case MotionEvent.ACTION_UP: Log.d("action", "ACTION_UP - "); action_down_x = 0; action_up_x = 0; difference = 0; break; } return false; //to allow the clicklistener to work after } })