title: drag and drop (checkmark if I drag the right image) android
body: <p>If I drag a countryTypical image and drop in imageCountry[n9] the application set the checkmark image on the right countryTypical image. 
  It happens if I drag the right countryTypical image and also if I drag the mistaken countryTypical image. I would like to correct the error.
  Many thanks...</p>
  
  <pre><code>String[] countryNames = {
          "Italy", "France", "Spain", "Germany", "Belgium", "Portugal", "Switzerland", "Great Britain"
  };
  
  int[] countryImages = {
          R.drawable.italy,
          R.drawable.france,
          R.drawable.spain,...
  };
  int[] countryFlags = {
          R.drawable.italian_flag,
          R.drawable.french_flag,
          R.drawable.spanish_flag,....
  };
  </code></pre>
  
  <p>In my OnCreate:</p>
  
  <pre><code>countryTypical1.setImageResource(countryFlags[n1]);
      countryTypical2.setImageResource(countryFlags[n2]);
      countryTypical3.setImageResource(countryFlags[n3]);
      countryTypical4.setImageResource(countryFlags[n4]);
      countryTypical5.setImageResource(countryFlags[n5]);
      countryTypical6.setImageResource(countryFlags[n6]);
      countryTypical7.setImageResource(countryFlags[n7]);
      countryTypical8.setImageResource(countryFlags[n8]);
  
      countryTypical1.setOnTouchListener(dragClick);
      countryTypical2.setOnTouchListener(dragClick);
      countryTypical3.setOnTouchListener(dragClick);
      countryTypical4.setOnTouchListener(dragClick);
      countryTypical5.setOnTouchListener(dragClick);
      countryTypical6.setOnTouchListener(dragClick);
      countryTypical7.setOnTouchListener(dragClick);
      countryTypical8.setOnTouchListener(dragClick);
  
      imageCountry.setOnDragListener(DropListener);
  </code></pre>
  
  <p>View.OnTouchListener dragClick = new View.OnTouchListener() {</p>
  
  <pre><code>    public boolean onTouch(View view, MotionEvent event) {
          if (event.getAction() == MotionEvent.ACTION_MOVE) {
              DragShadow dragShadow = new DragShadow(view);
  
              ClipData dragData = ClipData.newPlainText("", "");
              view.startDrag(dragData, dragShadow, view,0);
              return true;
          }
          return true;
      }
  };
  
  
  
  private class DragShadow extends View.DragShadowBuilder{
  
      public DragShadow(View view) {
          super(view);
      }
      @Override
      public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
          View view = getView();
          int height = view.getHeight();
          int width = view.getWidth();
  
          shadowSize.set(width, height);
          shadowTouchPoint.set(width, height);
      }
  
      @Override
      public void onDrawShadow(Canvas canvas) {
          getView().draw(canvas);
      }
  }
  
  
  View.OnDragListener DropListener = new View.OnDragListener() {
  
      @Override
      public boolean onDrag(View view, DragEvent event) {
          assignDropTrue(countryTypical1, event, n1);
          assignDropTrue(countryTypical2, event, n2);
          assignDropTrue(countryTypical3, event, n3);
          assignDropTrue(countryTypical4, event, n4);
          assignDropTrue(countryTypical5, event, n5);
          assignDropTrue(countryTypical6, event, n6);
          assignDropTrue(countryTypical7, event, n7);
          assignDropTrue(countryTypical8, event, n8);
          return true;
      }
  
  };
  
  
  
  private void assignDropTrue(ImageView countryTypical, DragEvent event, int n1){
      if (n9 == n1){
          int dragEvent = event.getAction();
          switch (dragEvent) {
              case DragEvent.ACTION_DROP:
                  countryTypical.setImageResource(R.drawable.vcheckmark);
          }}
  }
  </code></pre>