title: Perform a drag operation from a PopupWindow in Android
body: <p>I want to "Drag and Drop" items from a PopupWindow into the underlying View. The problem now is, when i dismiss the PopupWindow after a long click on an item, the underlying view does not receive any MotionEvents. This problem basically breaks down to delegating MotionEvents between views like in the drag-and-drop-between-views-issue as discussed <a href="https://stackoverflow.com/questions/4566287/how-to-implement-drag-and-drop-between-lists-in-android">here</a>. A solution was proposed <a href="http://doandroids.com/blogs/2010/6/25/android-drag-and-drop/" rel="nofollow noreferrer">here</a> but in my case this is not an option. I can't use an overlay view that lies on top of the PopupWindow, can I?</p>
  
  <p>The code below is a simplified version of my problem. I basically have one button that brings up the PopupWindow. On a long click on that PopupWindow it gets dismissed. Now the MotionEvents should be send to the underlying view again, but that does not happen (as you can see in the log output).</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Gravity;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.View.OnLongClickListener;
  import android.view.View.OnTouchListener;
  import android.widget.Button;
  import android.widget.PopupWindow;
  
  public class PopupWindowDragDropActivity extends Activity implements OnClickListener, OnTouchListener {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          findViewById(R.id.b1).setOnClickListener(this);
          findViewById(R.id.contents).setOnTouchListener(this);
      }
  
      @Override
      public void onClick(View v) {
          final PopupWindow p = new PopupWindow(this);
          p.setContentView(new Button(this));
          p.setHeight(100);
          p.setWidth(100);
          p.showAtLocation(findViewById(R.id.contents), Gravity.CENTER, 0, 0);
          p.getContentView().setOnLongClickListener(new OnLongClickListener() {
  
              @Override
              public boolean onLongClick(View v) {
                  v.post(new Runnable() {
                      @Override
                      public void run() {
                          p.dismiss();
                      }
                  });
  
                  return false;
              }
          });
      }
  
      @Override
      public boolean onTouch(View v, MotionEvent event) {
          Log.d("", "Action: " + event);
          return true;
      }
  }
  </code></pre>
  
  <p>Here is the simple XML layout I use:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:id="@+id/contents" &gt;
  
      &lt;Button
          android:id="@+id/b1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>