title: dialog.dismiss won't work.bugged?
body: <p>I have the following code.It shows a dialog with a textview and some buttons.When a button is pressed,the dialog should close.But it doesn't.Is it bugged ? I tried both dialog.dismiss and dialog.cancel but it just won't work.</p>
  
  <p>What's the solution ?</p>
  
  <pre><code>AlertDialog.Builder alert = new AlertDialog.Builder(
                      Gestionarez.this);
  
              final TextView Dtv = new TextView(Gestionarez.this);
                   printeaza=new Button(Gestionarez.this);
                   stergere=new Button(Gestionarez.this);
                   trimitere=new Button(Gestionarez.this);
              final AlertDialog dialog = alert.create();
  
              trimitere.setText("Trimite");
              trimitere.setTextSize(10);
              trimitere.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
  
                  }
              });
              printeaza.setText("Printeaza");
              printeaza.setTextSize(10);
              printeaza.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
                      dialog.dismiss();
                      dialog.cancel();
                  }
              });
              stergere.setText("Sterge");
              stergere.setTextSize(10);
              stergere.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
  
                      boolean deleted = file.delete();
  
                      Toast.makeText(Gestionarez.this, str+ " a fost sters ",
                              Toast.LENGTH_SHORT).show();
                      lv2.invalidateViews();
  
  
                  }
              });
              LinearLayout ldialog = new LinearLayout(Gestionarez.this);
              LinearLayout ldialogb = new LinearLayout(Gestionarez.this);
              ldialog.setOrientation(LinearLayout.VERTICAL);
              ldialogb.setOrientation(LinearLayout.HORIZONTAL);
              Dtv.setText(text);
              ldialog.addView(Dtv);
              ldialogb.addView(trimitere);
              ldialogb.addView(printeaza);
              ldialogb.addView(stergere);
              ldialog.addView(ldialogb);
              ldialogb.setGravity(Gravity.CENTER | Gravity.BOTTOM);
              Dtv.setGravity(Gravity.CENTER | Gravity.BOTTOM);
              Dtv.setPadding(60, 60, 60, 60);
              alert.setView(ldialog);
  
              alert.show();
  
          }
      });
  
  }
  </code></pre>