當按下一個按鈕,我使用一個稍微不同的方法,以保持該對話框打開:AlertDialog setOnShowListener從來沒有所謂
AlertDialog.Builder builder = new AlertDialog.Builder(NewTableActivity.this);
builder.setTitle(R.string.addComponent);
final EditText titleText = new EditText(NewTableActivity.this);
titleText.setHint(R.string.title);
builder.setView(titleText);
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int i){
dialogInterface.cancel();
}
});
builder.setPositiveButton(R.string.ok, null);
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener(){
@Override
public void onShow(DialogInterface dialogInterface){
Log.i("TEst", "Doung");
Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
}
}
對話框打開低一點(這個工程太),但日誌從未被稱爲
的可能的複製[爲什麼不昂秀中被調用我的自定義dialogfragment?](http://stackoverflow.com/questions/28522103/why-isnt-onshow-in-my-custom -dialogfragment-being-invoked) –