我可以在单击PositiveButton之后不关闭我的AlertDialog吗?
我想保留对话框以在ArrayAdapter listWords上显示一些更新。
这是我的代码。
AlertDialog.Builder sayWindows = new AlertDialog.Builder(MapActivity.this);
final EditText saySomething = new EditText(MapActivity.this);
sayWindows.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
say = userName + " Says: "+saySomething.getText();
showPosition.setText(say);
}
});
sayWindows.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
sayWindows.setAdapter(listWords, null);
sayWindows.setView(saySomething);
sayWindows.create().show();
最佳答案
看完@Little Child解决方案后,我尝试做这个。让我们知道这是否适合您。
AlertDialog.Builder sayWindows = new AlertDialog.Builder(
MapActivity.this);
final EditText saySomething = new EditText(MapActivity.this);
sayWindows.setPositiveButton("ok", null);
sayWindows.setNegativeButton("cancel", null);
sayWindows.setAdapter(listWords, null);
sayWindows.setView(saySomething);
final AlertDialog mAlertDialog = sayWindows.create();
mAlertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button b = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Do something
say = userName + " Says: "+saySomething.getText();
showPosition.setText(say);
}
});
}
});
mAlertDialog.show();
关于android - Android在单击PositiveButton后不要关闭AlertDialog,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26086848/