Prevent drag drop of custom mimetype to EditText

前端 未结 4 2188
南旧
南旧 2021-02-20 02:41

I have a custom mime type which I am intending to use to drag and drop application objects within the app. This seems to be working but I\'m finding that the EditText fields ar

4条回答
  •  我在风中等你
    2021-02-20 03:11

    I encountered a similar issue in that I did not want a layout to accept the drop action.

    Attach a drag listener to your edit field via the setOnDragListener.

    edtText.setOnDragListener(new MyDragListener());
    

    Check whether the target view in the onDrag event is your edit text.

    class MyDragListener implements OnDragListener {
    
        @Override
        public boolean onDrag(View v, DragEvent event) {
    
          switch (event.getAction()) {
             case DragEvent.ACTION_DROP:
                 //check whether it has been dropped onto your edit text
                  if(v!=edtText)
                      //your code here
        }
    

提交回复
热议问题