title: How to register a DragEvent while already inside one and have it listen in the current DragEvent?
body: <p>My question is is related to the Drag and Drop API in Android. I apologize if my question was confusing. But essentially, when you want to start a Drag and Drop operation, you must invoke <code>startDrag()</code> on a <code>View</code>. You pass it in some info, and then you give it a <code>OnDragListener</code> in which to listen for a <code>View</code> which is being dragged. When the a drag is started, in my example a long press, all the Views that can accept any info are registered with the system to accept this info. It would make more sense if you quickly read through some of this in the android docs for <a href="http://developer.android.com/guide/topics/ui/drag-drop.html" rel="nofollow">Drag and Drop</a>. But thats a quick overview of how it works assuming you havent used it before and would like to.</p>
  
  <p>Now my question is essentially in an issue I have come across. I would like to create a <code>View</code> while the <code>onDragListener</code> is running that also accepts system info on a currently being dragged <code>View</code>. Problem is its not working. I am not surprised as the View was not registered when when the Drag operation first started. The question is how can I register it on the fly. The android docs shows you how to register it in the beginning but not when its already in one.</p>
  
  <p><strong>MyDragListener</strong> (Code for my onDragListener. Right now only playing with it.)</p>
  
  <hr>
  
  <pre><code>protected class MyDragListener implements View.OnDragListener {
  
      @Override
      public boolean onDrag(View v, DragEvent event) {
  
          // Defines a variable to store the action type for the incoming event
          final int action = event.getAction();
  
          // Handles each of the expected events
              switch(action) {
  
                  case DragEvent.ACTION_DRAG_STARTED:
                      // Determines if this View can accept the dragged data
                      /*The way it works is it essentially turns anything that can accept stuff to Blue 
                       * or whatever color. It also does not need to do anything in terms of showing it can accept anything.*/
                      if(event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                          v.setBackgroundColor(Color.BLUE);
  
                          return (true);
  
                      } else {
                          return (false);
                      }
                  //break;
  
                  case DragEvent.ACTION_DRAG_ENTERED:
                      v.setBackgroundColor(Color.YELLOW);
                      Toast.makeText(v.getContext(), "Height is: "+v.getHeight(), Toast.LENGTH_SHORT).show();
                      return true;
                  //break;
  
                  case DragEvent.ACTION_DRAG_LOCATION:
                      //this is triggered right after ACTIN_DRAG_ENTERED
                      Log.d("TestActivity", "Location of the View you are dragging is x: "+event.getX()+" y: "+event.getY());
                      if(v.getHeight()-10 &lt; event.getY() &amp;&amp; v.getHeight() &gt; event.getY()&amp;&amp; showingView == false ) {
  
                              //here you are checking if its in the lower bound of the view
                              LayoutInflater inflater = LayoutInflater.from(v.getContext());
                              LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.some_text, table, false);
                              ((TextView)layout.findViewById(R.id.da_text)).setText("Some text");
                              layout.setTag("Empty");
                              layout.startDrag(ClipData.newPlainText("Empty", "Empty"), new View.DragShadowBuilder(), null, 0);
                              table.addView(layout, Integer.parseInt(v.getTag().toString())+1);
                          showingView = true;
                      }
                      return true;
  
  
                  case DragEvent.ACTION_DRAG_EXITED:
                      v.setBackgroundColor(Color.BLUE);
                      return true;
                  //break;
  
                  case DragEvent.ACTION_DROP:
                      //this is obvious, gets the data in the view that was dropped
                      return true;
  
                  case DragEvent.ACTION_DRAG_ENDED:
                      v.setBackgroundColor(Color.WHITE);
                      return true;
  
  
              }//end of switch
  
          return false;
      }
  
  }//end of MyDragListener
  </code></pre>
  
  <p><strong>Edit 1</strong></p>
  
  <p>So I tried a different approach. I decided to have a holder for my <code>LinearLayout</code> which would be an item in the <code>TableLayout</code>. That way I would register the <code>OnDragListener</code> then I could just hold it until I needed it. That failed. The first time I used it, even if I added it to the TableLayout, it would not Listen to any drags, but when I dropped the drag and then long pressed it, it worked. So it has something to do with the fact that its invisible, and then its not. So by default it does not do anything when its invisible, and I am not sure how to make that not happen, and allow me to have it do something even when its invisible. Any ideas?</p>