注册ListView的onTouchListener()
具体代码如下:
listview.setOnTouchListener(new OnTouchListener() { float x,y,ux,uy; @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if(event.getAction()==MotionEvent.ACTION_DOWN){ x=event.getX(); y=event.getY(); } if(event.getAction()==MotionEvent.ACTION_UP){ ux=event.getX();uy=event.getY(); int p1=store_history.pointToPosition((int)x, (int)y); int p2=store_history.pointToPosition((int)ux, (int)uy); if(p1==p2&&Math.abs(x-ux)>10){ listviewadapter.getData().remove(p1); listviewadapter.notifyDataSetChanged(); } return true; } return false; } });