title: implementing a button inside a popup window for android
body: <p>bellow you can see a script that displays the data from a SQLite database in a popup window. My question is that how can I implement a button inside that window to accomplish some tasks</p>
  
  <p>here is the code:</p>
  
  <pre><code>package com.example.asus.sqlliteproject;
  
  import android.app.AlertDialog;
  import android.database.Cursor;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class MainActivity extends AppCompatActivity {
  
      DataBaseHelper myDB;
      EditText Name,LastName,Grades;
      Button AddData,ViewData;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          myDB = new DataBaseHelper(this);
          Name = (EditText)findViewById(R.id.name);
          LastName = (EditText)findViewById(R.id.lastName);
          Grades = (EditText)findViewById(R.id.Grades);
          AddData = (Button)findViewById(R.id.addDataButton);
          ViewData = (Button)findViewById(R.id.view);
          addData();
  
      }
      public void addData () {
          AddData.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  boolean inserted = myDB.insertData(Name.getText().toString(),
                          LastName.getText().toString(),
                          Grades.getText().toString());
                  if (inserted) {
                      Toast.makeText(MainActivity.this, "Text Inserted!", Toast.LENGTH_SHORT).show();
                  } else
                      Toast.makeText(MainActivity.this, "Unsuccessful!", Toast.LENGTH_SHORT).show();
              }
          });
      }
  
      public void viewAll () {
          ViewData.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Cursor res = myDB.getAllData();
                  if (res.getCount() ==0){
                      // show some message
                      showMessage("Error", "Nothing found");
                      return;
                  }
                  StringBuffer buffer = new StringBuffer();
                  while (res.moveToNext()) {
                      buffer.append("ID :"+ res.getString(0)+"\n");
                      buffer.append("Name :"+ res.getString(1)+"\n");
                      buffer.append("LastName :"+ res.getString(2)+"\n");
                      buffer.append("Grade :"+ res.getString(3)+"\n\n");
                  }
                  // show all data here
                  showMessage("Data",buffer.toString());
  
              }
          });
  
      }
  
      public void showMessage (String title, String message) {
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setCancelable(true);
          builder.setTitle(title);
          builder.setMessage(message);
          builder.show();
      }
  
  }
  </code></pre>
  
  <p>and here is a screen shot of the app and what I want to implement:</p>
  
  <p><a href="http://i.stack.imgur.com/oN0u4.jpg" rel="nofollow">Click here for image</a></p>