Show popup over another popup window in android
<p>I have a problem that I am opening a Popup window in my application and I want to open another Popup window on button click which contains in a previous Popup, means I want to open another popup from  previous opened Popup Window. When I am writing code for this as simple as previous popUp then it responds BadTokenException. Please suggest me any solution regarding the same.</p>

<p><strong>Code:</strong></p>

<pre><code>popUp = new PopupWindow(this);
     popUpOver = new PopupWindow(this);
     layout = new LinearLayout(this);
     mainLayout = new LinearLayout(this);
     mLayoutPopUp = new LinearLayout(this);
     tv = new TextView(this);
     but = new Button(this);
     butPopup = new Button(this);
     butPopup.setText("Click Me");
     but.setText("Click Me");
     but.setOnClickListener(new OnClickListener() {

      public void onClick(View v) {
       if (click) {
        popUp.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
        popUp.update(50, 50, 300, 80);
        click = false;
       } else {
        popUp.dismiss();
        click = true;
       }
      }

     });
     butPopup.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (clickOver) {
                popUpOver.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
                popUpOver.update(50, 50, 300, 80);
                clickOver = false;
               } else {
                popUpOver.dismiss();
                clickOver = true;
               }
        }
    });
     params = new LayoutParams(LayoutParams.WRAP_CONTENT,
       LayoutParams.WRAP_CONTENT);
     layout.setOrientation(LinearLayout.VERTICAL);
     mLayoutPopUp.addView(butPopup, params);
     tv.setText("Hi this is a sample text for popup window");
     popUpOver.setContentView(mLayoutPopUp);
     layout.addView(mLayoutPopUp, params);
     popUp.setContentView(layout);
     // popUp.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
     mainLayout.addView(but, params);
     setContentView(mainLayout);
</code></pre>

<p>Thanks in advance.</p>
