3

我正在创建一个可拖动的 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监听器吗?

4

1 回答 1

2

您可以使用 aonLongClickListener开始拖动。这应该允许您编辑该字段,因为控件的默认单击或触摸侦听器不会被覆盖

尝试这样的事情来启动你的拖动启动

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;
    }
};

希望这可以帮助

于 2013-11-12T05:12:24.340 回答