title: Ok Button for Alert Dialog on Android
body: <p>This is my code for an alert, it shows a message when a button is pressed. How can I make an OK Button to dismiss?</p>
  <pre><code>    Button bm1 = (Button) findViewById(R.id.button1);
      bm1.setOnClickListener(new View.OnClickListener() {
          
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              AlertDialog alert = new AlertDialog.Builder(screen4.this).create();
              alert.setTitle(&quot;Doctor&quot;);
              alert.setMessage(&quot;message&quot;);
              alert.setCancelMessage(null);
              alert.show();
          }
      });
  }}      
  </code></pre>
  <p>I have put <code>alert.setCancelMessage(null)</code> but it doesn't show any button to dismiss.</p>
  <p><strong>Solution:</strong></p>
  <pre><code>      Button bm1 = (Button) findViewById(R.id.button1);
         bm1.setOnClickListener(new View.OnClickListener() {
          
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              Builder alert = new AlertDialog.Builder(screen4.this);
              alert.setTitle(&quot;Doctor&quot;);
              alert.setMessage(&quot;message&quot;);
              alert.setPositiveButton(&quot;OK&quot;, null);
              alert.show();
          }
      });
  </code></pre>