2011-07-22 4 views
0

AlertDialogに問題があります:私はAlertDialogが正のボタンをクリックするとtrueを返し、負のボタンをクリックするとfalseを返します。この関数は、ユーザーがボタンをクリックするまでプログラムをブロックする必要があります。[Android] Alertdialogはブール値を返しますonclick

マイコード:あなたは2つの機能を実装する必要があり、あなたの活動に

public static boolean errorMD5(Context context){ 
    AlertDialog.Builder builder = new AlertDialog.Builder(context); 
    builder.setTitle(context.getString(R.string.error)); 
    builder.setIcon(android.R.drawable.ic_dialog_alert); 
    builder.setMessage(R.string.errorMD5); 
    builder.setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      //The function return true 
     } 
    }); 
    builder.setNegativeButton("No", new DialogInterface.OnClickListener() {   
      @Override 
      public void onClick(DialogInterface arg0, int arg1) { 
       //The function return false      
      } 
    }); 
    AlertDialog alert = builder.create(); 
    alert.show(); 
} 

答えて

1

onYesPressed() and onNoPressed() 

これらをダイアログから呼び出します。

それとも、

onUserDismissDialog(boolean allow) 

と、ダイアログOnClickListenerからこの関数を呼び出すブールパラメータを取るだけの機能を実装することができます。

+0

いいえ、動作しませんこの関数で自分のアクティビティで関数を呼び出すことができません。この関数は別のクラスにあります。 – Guillaume

+0

MyActivity.this.onUserDismissDialog(true)を呼び出す必要があります。 –

+0

それはうまく動作します、ありがとう! – Guillaume

関連する問題