0

I want to keep dialog box open if speak again button is pressed but when i presses it, dialogue closes. Please help me how to keep open dialogue

public class MainActivity extends Activity implements OnClickListener{

    Button b1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(this);

    }

    @Override
    public void onClick(View arg0) {
         final Builder ad = new AlertDialog.Builder(this);

         ad.setCancelable(false);



        ad.setNegativeButton("Ok",  new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int arg1) { 
            }
        });     


        ad.setPositiveButton("Speak Again", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog,int arg1) {


            }});
        ad.show();

    }
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • please [refer this.](http://stackoverflow.com/a/7636468/2345913) – CRUSADER Jun 18 '13 at 05:11
  • possible duplicate :http://stackoverflow.com/questions/6142308/android-dialog-keep-dialog-open-when-button-is-pressed?rq=1 http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked – Rachita Nanda Jun 18 '13 at 05:12

2 Answers2

0

Try this one.

AlertDialog AD = new AlertDialog.Builder(YourActivity.this)
        .setTitle("Title")
        .setMessage("Message")
        .setNegativeButton("Ok", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        })
        .setPositiveButton("Speak Again", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog_main, int which) {
                // TODO Auto-generated method stub

            }
        }).show();
Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
0

well, u r using dialog box. that means it'll close once a button is pressed. u can reopen the dialog box when getting the "speak again" button or u can create your own Jform so it won't be closed if "speak again" button is pressed.

i would suggest you create your own form

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70