title: How to get the view while drag & dropping in android?
body: <p>I have implemented the drag &amp; drop feature in my app. I have four <code>textview</code> views &amp; I have drag &amp; drop. But I want to know which <code>textview</code> was dragged &amp; dropped? I want to know which <code>textview</code> is the drop target &amp; which <code>textview</code> is dragged by their name as defined in my code.</p>
  <p>Following is the code for that:</p>
  <p><strong>code for the init the views</strong></p>
  <pre><code>public void initView()
  
  {
      p_one = (TextView) findViewById(R.id.tgoal_tvone);
      p_two = (TextView) findViewById(R.id.tgoal_tvtwo);
      p_three = (TextView) findViewById(R.id.tgoal_tvthree);
      p_four = (TextView) findViewById(R.id.tgoal_tvfour);
      query = (ImageView) findViewById(R.id.tgoal_img_query);
      tv_contentOne=(TextView)findViewById(R.id.tgoal_tvoneContent);
      tv_contentTwo=(TextView)findViewById(R.id.tgoal_tvtwoContent);
      tv_contentThree=(TextView)findViewById(R.id.tgoal_tvthreeContent);
      tvContentFour=(TextView)findViewById(R.id.tgoal_tvfourContent);
      
      query.setOnClickListener(this);
      
      
      //set touch listeners
      tv_contentOne.setOnTouchListener(new ChoiceTouchListener());
      tv_contentTwo.setOnTouchListener(new ChoiceTouchListener());
      tv_contentThree.setOnTouchListener(new ChoiceTouchListener());
      tvContentFour.setOnTouchListener(new ChoiceTouchListener());
              
      //set drag listeners
      tv_contentOne.setOnDragListener(new ChoiceDragListener());
      tv_contentTwo.setOnDragListener(new ChoiceDragListener());
      tv_contentThree.setOnDragListener(new ChoiceDragListener());
      tvContentFour.setOnDragListener(new ChoiceDragListener());
      
      
      
      /**set up the action bar**/
      
      ActionBar bar = getActionBar();
      bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(&quot;#0099CC&quot;)));
      bar.setTitle(getResources().getString(R.string.tgoal_header));
      bar.setDisplayHomeAsUpEnabled(true);
      bar.setHomeButtonEnabled(true);
  
  }
  </code></pre>
  <p><strong>code for getting the drop view</strong></p>
  <pre><code>class ChoiceDragListener implements OnDragListener
      {
          int count=0;
  
          @Override
          public boolean onDrag(View v, DragEvent event) {
              // TODO Auto-generated method stub
              View dragView = (View) event.getLocalState();
              switch (event.getAction()) 
              {
              
              case DragEvent.ACTION_DRAG_STARTED:
                  //no action necessary
                   
                  break;
              case DragEvent.ACTION_DRAG_ENTERED:
                  //no action necessary
                  break;
              case DragEvent.ACTION_DRAG_EXITED:        
                  //no action necessary
                  break;
              case DragEvent.ACTION_DROP:
                  
                  //handle the dragged view being dropped over a drop view
                  //handle the dragged view being dropped over a target view
                  View view = (View) event.getLocalState();
                  //stop displaying the view where it was before it was dragged
                  //view dragged item is being dropped on
                  TextView dropTarget = (TextView) v;
                  //view being dragged and dropped
                  TextView dropped = (TextView) view;
                  String droppedTarget=dropTarget.getText().toString();
                   dropTarget.setText(dropped.getText());
                   dropped.setText(droppedTarget);
                   
                  //make it bold to highlight the fact that an item has been dropped
                  dropTarget.setTypeface(Typeface.DEFAULT_BOLD);
                  dropTarget.setBackgroundColor(getResources().getColor(R.color.papya_orange));
                  Log.i(&quot;log&quot;, &quot;TV Dropped&quot;);
                  if(dropTarget==p_one)
                  {
                      Log.i(&quot;log&quot;, &quot;Drop View is First TextView&quot;);
                      
                  }
                  
              
                  break;
              case DragEvent.ACTION_DRAG_ENDED:
                  //no action necessary
                  break;
              default:
                  break;
          }
              return true;
          }
          
      }
  </code></pre>