Gali
Gali

Reputation: 14953

android:Strange behavior on dialogbox

i have Strange problem on dialog box.

I increase the value of X and sending it to dialogbox

on the dialogbox - I keep seeing the same value.

public String TMP;
int X=1;

.
.
.

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case MENU_ABOUT:
            X++;
            TMP = String.valueOf(X);
            showDialog(ABOUT);
            break;
        }
        return super.onOptionsItemSelected(item);
  }

.
.
.

 protected Dialog onCreateDialog(int id, Bundle args)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if (id==0) 
        {
             builder.setTitle(TMP);
             builder.setIcon(R.drawable.ic_launcher);
             builder.setCancelable(false);
             builder.setPositiveButton("Back", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int id) {
                      }
                  });
              AlertDialog alert = builder.create();
              return(alert);
        }
        AlertDialog alert = builder.create();
        return(alert);
    }

and I keep seeing 2 all wase

Upvotes: 1

Views: 81

Answers (1)

Phillip Fitzsimmons
Phillip Fitzsimmons

Reputation: 2945

onCreateDialog is (typically) called only once when a dialog is first created. If you want to modify a dialog you need to implement onPrepareDialog.

Upvotes: 1

Related Questions