1

In my program I have used an alert dialog box on onclick event. But after running my program on event onclick the alert dialog box opens and allows filling information in it. and then on click of ok button alert dialog if condition is matched than data will be submitted and intent will pass otherwise in toast msg it will show something like enter correct password or loginid etc. but when on second click of button on which I have set alertdialogbox the thread msg will appear and it will close the program so what is the solution for this.

Hope for your concern. Thanking you

gprathour
  • 14,813
  • 5
  • 66
  • 90
Khan
  • 7,585
  • 3
  • 27
  • 44
  • Could you add your LogCat output? – Alexander Kulyakhtin Nov 29 '11 at 09:11
  • AlertDialog requires an activity running in background on which it will be displayed keeping the activity in background. So can u please post your code snippet such that we can find a better solution for your problem if you wont mind. – KK_07k11A0585 Nov 29 '11 at 09:18

3 Answers3

0

Go through the overridden methods

  • OnCreateDialog()
  • OnPrepareDialog()

Ref: http://developer.android.com/guide/topics/ui/dialogs.html

just for an idea

@Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DataMember.DIALOG_ALERT:
                return new AlertDialog.Builder(this)
                        .setCancelable(false)
                        .setMessage("")
                        .setPositiveButton("Ok",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int id) {
                                        //do your code
//if () { call intent} else {do nothing}

                                    }
                                }).create();
    }
    }
Jayabal
  • 3,619
  • 3
  • 24
  • 32
0

Clicking on positive or negative button finally results in closing the dialog.So trick you can do is:

  1. Prepare a method that opens dialog

    public void openDialog() {

      // code to open dialog
    

    }

  2. call the method where you check the codition

    public void openDialog() {

      // code to open dialog
    
      ...
    
      //in button click{ 
    
         if(codition matches)
              //do something and close the dialog
         else
              openDialog(); //that will reopen the dialog
        }      
    

    }

Hiral Vadodaria
  • 19,158
  • 5
  • 39
  • 56
0

why not used custom popup ?.

see http://virenandroid.blogspot.com/2011/11/custom-popupwindow-android.html

Viren Savaliya
  • 520
  • 1
  • 6
  • 18