2012-03-28 10 views
0

私のコードのNegativeButtonを設定します方法として以下のAlertDialog.Builder unclickable

AlertDialog.Builder dialog = new AlertDialog.Builder(this); 
dialog.setTitle("Dialog"); 

dialog.setPositiveButton("Check", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface arg0, int arg1) { 
    if(condition) { 
     //set NegativeButton unclickable 
    } else { 
     //set NegativeButton clickable 
    } 
    } // end of onClick 
}); 

dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface arg0, int arg1) { 
    //do something 
    } 
}); 

はどのようNegativeButtonをクリックしてunclickable設定しますか? onclickの状態をチェックするためのコードの下

... ... 

AlertDialog alertDialog = alertDialogBuilder.create(); 
alertDialog.show(); 

if(condition) { 
    //set NegativeButton unclickable 
    alertDialog.getButton(Dialog.BUTTON_NEGATIVE).setClickable(false); 
} else { 
    //set NegativeButton clickable 
    alertDialog.getButton(Dialog.BUTTON_NEGATIVE).setClickable(true); 
} 

答えて

1

用途:

try { 
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); 
field.setAccessible(true); 
field.set(dialog, false); 
} 
catch(Exception e) { 
e.printStackTrace(); 
} 

これは、それは何もしないことができますが、それはまだクリッカブル

1

はこれを試してみてください。

+0

NULLポインタエラー – brian

+0

@brian、おそらくalert alertDialog.show()コールが必要です。まず、私の答えを更新しました。 – yorkw

関連する問題