0

I am developing an android app using drag and drop. when i drag a button. then i want to identify the button by name (get the button name). I want to get the button name in DragEvent.ACTION_DROP.

My code is shown below.

 drop.setOnDragListener(new View.OnDragListener() {
  @Override
  public boolean onDrag(View v, DragEvent event) {
    //return false;
      View dragView = (View) event.getLocalState();



      final int action = event.getAction();
    switch(action) {

      case DragEvent.ACTION_DRAG_STARTED:
          //Log.d("LockView", "ACTION_DRAG_STARTED");

        break;

      case DragEvent.ACTION_DRAG_EXITED:
          //Log.d("LockView", "ACTION_DRAG_EXITED");
        break;

      case DragEvent.ACTION_DRAG_ENTERED:
          //Log.d("LockView", "ACTION_DRAG_ENTERED");
        break;

      case DragEvent.ACTION_DROP:{
        failure = failure+1;
          Log.d("LockView", "ACTION_DROP");



        return(true);
      }

      case DragEvent.ACTION_DRAG_ENDED:{

          //Log.d("LockView", "ACTION_DRAG_ENDED");
        return(true);

      }

      default:
        break;
    }

    return true;
  }

And my button code is

btn1.setOnTouchListener(new OnTouchListener() {@Override public boolean onTouch(View v, MotionEvent event) {
            Log.d("LOGTAG", "Touched c"+c);
            ClipData data = ClipData.newPlainText("", "");
            View.DragShadowBuilder shadow = new View.DragShadowBuilder(btn1);
            v.startDrag(data, shadow, v, 0);
            Log.d("LOGTAG", "Touched");
            if(SystemClock.elapsedRealtime() - c < 1000) {
                if (position > -1 && position < 4) {
                    nums[position] = 1;
                }
                setPosition(position);
            }

            c=SystemClock.elapsedRealtime();
            // TODO Auto-generated method stub
            switch (event.getAction()) {

                case MotionEvent.ACTION_DOWN:
                    startX = event.getX();
                    startY = event.getY();
                    break;
                case MotionEvent.ACTION_UP:
                    float endX = event.getX();
                    float endY = event.getY();
                    if (isAClick(startX, endX, startY, endY)) {
                        Log.d("LockView", "clicked");
                        /*if (position > -1 && position < 4) {
                            nums[position] = 1;
                        }
                        setPosition(position);*/
                    } else {




                    }
                    break;
            }
            v.getParent().requestDisallowInterceptTouchEvent(true); //specific to my project
            return false;
        }
    });

When i drag the button btn1. Then i want to identify the button.

0 Answers0