註冊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){
//p1為item的position,得到position了,刪除應該沒問題了吧
//Cursor cursor = (Cursor) houseAdapter.getItem(p1);
//Contacts.mLBSService.deleteFavorite(DBUtil.cursorToHouseInfo(cursor).getId(), null);
//Log.d("sad", "cursor requery : " + cursor.requery());
listviewadapter.getData().remove(p1);
listviewadapter.notifyDataSetChanged();
}
return true;
}
return false;
}
});