This article describes the method of Android to not close the dialog box when clicking the button on AlertDialog. Share it for your reference. The details are as follows:
During the development process, sometimes there are such requirements:
After clicking a button, a dialog box is displayed. There is an input box on the dialog box, and there are two buttons "Confirm" and "Cancel". When the user clicks the confirm button, it is necessary to judge the content of the input box. If the content is empty, the dialog box will not be closed and the toast prompt will be prompted.
When using the Create dialog, you can set the click event of the cancel button and the confirm button using two methods. However, the problem is that as long as the user clicks the confirm button or the cancel button, the system will automatically close the dialog box.
The solution to this problem is:
(1) Use the text of the setting confirmation button, but do not add listening. Right now:
(2) Get the AlertDialog object:
();
(3) Get the confirmation button on the dialog box, and then add a normal one to the button. When the user input is correct, call () manually to close the dialog box.
@Override
public void onClick(View v) {
String cardNum = ().toString().trim();
if (() == 0) {
(mActivity, "Please enter a number");
return;
}
//send
sendProfile(cardNum);
();
}
});
The problem was solved perfectly.
I hope this article will be helpful to everyone's Android programming design.