title: button click outside of dialog
body: <p>I've 2 buttons in my layout. First shows toast and another shows dialog. I want to be able to click the first button and show toast, even when dialog is showing. At present when I touch the first button (for first time), the dialog gets dismissed and when I again touch the first button (for second time), then the toast shows. What I want is to show the toast on the first click. Is it possible?</p>
  
  <pre class="lang-css prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.sam.myregistrationapplication.MainActivity"&gt;
  
  
      &lt;Button
          android:id="@+id/btn1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="50dp"
          android:text="close dialog"/&gt;
  
      &lt;Button
          android:id="@+id/btn2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/btn1"
          android:layout_margin="50dp"
          android:text="show dialog"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code>public class MainActivity extends AppCompatActivity {
  
      Button btn1, btn2;
      Dialog pDialog;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          btn1 = (Button)findViewById(R.id.btn1);
          btn2 = (Button)findViewById(R.id.btn2);
  
          btn1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Toast.makeText(getApplicationContext(), "First Button", Toast.LENGTH_SHORT).show();
              }
          });
  
  
          btn2.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  pDialog = new Dialog(MainActivity.this);
                  pDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  pDialog.setContentView(R.layout.alertdialog);
  
  
                  pDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
  
  
  
                  Button dialogButton = (Button) pDialog.findViewById(R.id.btn3);
  
                  dialogButton.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          pDialog.dismiss();
                      }
                  });
  
                  pDialog.show();
  
              }
          });
  
      }
  }
  </code></pre>