我在AlertDialog中有一个EditText。我想在EditText中有一些输入时忽略它,否则显示Toast提示用户输入数据。
目前,当编辑文本有数据时,对话框正确解除。此外,当edittext为空时,将显示toast。但是,即使EditText为空并且稍后显示Toast消息,对话框仍然会解除。
我不希望ALertDialog被解雇,并且在显示Toast后,EditText应该再次获得焦点。
这是我的代码: -
builder.setPositiveButton("Post", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
boolean worked = true;
postedComment = input1.getText().toString();
if(postedComment.length()==0 || postedComment=="" || postedComment.matches(""))
{
Toast.makeText(NewsDetails.this, "Please enter a comment.", Toast.LENGTH_LONG).show();
input1.findFocus();
worked = false;
}
else if(worked && postedComment!="")
{
dialog.dismiss();
pd = new ProgressDialog(NewsDetails.this);
pd.setMessage("Posting..");
pd.show();
pd.setCancelable(true);
PostComments(postedComment);
}
})
.setCancelable(false);
alert = builder.create();
alert.setCanceledOnTouchOutside(true);
alert.show();