dro*_*ter 9 android listview drag-and-drop
嗨,我正在尝试拖放ListView.它很棒.但我失去了点击和滚动的能力.我如何保留这两个?我认为长按该项目而不是正常按下时会发生拖放.这是我的onTouch,它位于扩展ListView的MyListView中
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
final int x = (int) ev.getX();
final int y = (int) ev.getY();
if (action == MotionEvent.ACTION_DOWN && x < this.getWidth()/4) {
this._dragMode = true;
}
if (!this._isDragNDrop)
return super.onTouchEvent(ev);
switch (action) {
case MotionEvent.ACTION_DOWN:
this._startPosition = pointToPosition(x,y);
if (this._startPosition != INVALID_POSITION) {
int mItemPosition = this._startPosition - getFirstVisiblePosition();
this._dragPointOffset = y - getChildAt(mItemPosition).getTop();
this._dragPointOffset -= ((int)ev.getRawY()) - y;
startDrag(mItemPosition,y);
drag(x,y);
}
break;
case MotionEvent.ACTION_MOVE:
drag(x,y);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
default:
this._dragMode = false;
//_isDragNDrop = false;
this._endPosition = pointToPosition(x,y);
stopDrag(this._startPosition - getFirstVisiblePosition());
if (this._dropListener != null && this._startPosition != INVALID_POSITION && this._endPosition != INVALID_POSITION)
this._dropListener.onDrop(this._startPosition, this._endPosition);
break;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10550 次 |
| 最近记录: |