2012-04-05 89 views
1

我有對話框的奇怪問題。android:奇怪的對話框行爲

我增加X的值並將其發送到在對話框對話框

- 我一直看到相同的值。

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); 
    } 

,我一直看到2所有哇塞

回答

1

onCreateDialog是(典型值)稱爲只有當第一次創建一個對話框一次。如果你想修改一個對話框,你需要實現onPrepareDialog。

+0

感謝您的幫助,您可以寫一個小樣本或在哪裏更改我的代碼,它將起作用嗎? (我還是新的Android上.....) – Gali 2012-04-05 10:20:16