我正在创建一个可拖动的editText,我使用editText来允许用户更改文本。但我现在的问题是我不能再编辑文本,因为它检测到文本的触摸/拖动。
对此有何解决方案?
private final class MyTouchListener implements OnTouchListener {
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
ClipData data = ClipData.newPlainText("", "");
DragShadowBuilder shadowBuilder = new DragShadowBuilder(view);
view.startDrag(data, shadowBuilder, view, 0);
view.setVisibility(View.VISIBLE);
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_HOVER_EXIT:
break;
}
return true;
}
}
我有拖拽监听器
class MyDragListener implements OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
paramsBlock = new RelativeLayout.LayoutParams(view.getWidth(), view.getWidth());
paramsBlock.leftMargin = (int) event.getX() - (view.getWidth()/2);//- ((imageView.getWidth()/9)/2);
paramsBlock.topMargin = (int) event.getY() -(view.getHeight()/2);//-((imageView.getWidth()/9)/2);
view.setLayoutParams(paramsBlock);
break;
case DragEvent.ACTION_DRAG_ENDED:
default:
break;
}
return true;
}
}
是否可以使用onLongClick
听众?
答案 0 :(得分:2)
您可以使用onLongClickListener
开始拖动。这应该允许您编辑该字段,因为控件的默认点击或触摸监听器不会被覆盖
尝试使用类似的内容进行拖动
OnLongClickListener longClickListener = new OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
ClipData data = ClipData.newPlainText("", "");
DragShadowBuilder shadowBuilder = new DragShadowBuilder(view);
view.startDrag(data, shadowBuilder, view, 0);
view.setVisibility(View.VISIBLE);
return true;
}
};
希望这有帮助