View.OnTouchListener gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(context, "on long press...........",
Toast.LENGTH_SHORT).show();
return gestureDetector.onTouchEvent(event);
}
};
listview.setOnTouchListener(gestureListener);
,班级是
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return true;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// viewFlipper.setInAnimation(slideRightIn);
// viewFlipper.setOutAnimation(slideRightOut);
// viewFlipper.showPrevious();
}
} catch (Exception e) {
// nothing
}
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
Log.e("Item Click", "Item Click");
return super.onSingleTapConfirmed(e);
}
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(context, "on long press...........",
Toast.LENGTH_SHORT).show();
}
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(context, "on show press...........",
Toast.LENGTH_SHORT).show();
}
}
所以请帮我刷一下如何显示删除按钮代替添加按钮。
答案 0 :(得分:0)
你必须在这里获取/创建删除按钮,并且必须处理这个的onClick()事件...并且对于设置布局,你必须将x和y位置实际传递到它应该显示的位置......
case MotionEvent.ACTION_UP: {
upX = event.getX();
upY = event.getY();
float deltaX = downX - upX;
float deltaY = downY - upY;
// horizontal swipe detection
if (Math.abs(deltaX) > MIN_DISTANCE) {
// left or right
if (deltaX < 0) {
mSwipeDetected = Action.LR;
return false;
}
if (deltaX > 0) {
mSwipeDetected = Action.RL;
deleteRow = (Button) v
.findViewById(R.id.btnNoteListItemDelete);
deleteRow.setVisibility(0);
deleteRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("DELETING THIS ROW");
deleteRow.setVisibility(View.GONE);
}
});
return true;
}
}
mSwipeDetected = Action.Click;
return false;
}
}
return false;
}