@Override
protected Dialog onCreateDialog(int id)
{
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Test");
alert.setIcon(R.drawable.logo1);
alert.setMessage("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus.");
LinearLayout lila1= new LinearLayout(this);
lila1.setOrientation(1); //1 is for vertical orientation
final EditText input = new EditText(this);
final EditText input1 = new EditText(this);
input.setId(0);
input1.setId(1);
input.setHint("Enter your email");
input1.setHint("Enter your message");
input1.setHeight(200);
lila1.addView(input);
lila1.addView(input1);
alert.setView(lila1);
alert.setPositiveButton("Send", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
String value = input.getText().toString().trim();
String value1 = input1.getText().toString().trim();
int emailIn= input.getText().toString().length();
int message=input1.getText().toString().length();
if( emailIn == 0 || message==0 )
{
if(emailIn==0)
{
input.setError("Name is Required");
//DialogBox should not close.
}
if(message==0)
{
input1.setError("Description is Required");
//DialogBox should not close.
}
}
else
{
// Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();
// Toast.makeText(getApplicationContext(), value1, Toast.LENGTH_SHORT).show();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{getResources().getString(R.string.toEmail)});
email.putExtra(Intent.EXTRA_SUBJECT, "Test");
email.putExtra(Intent.EXTRA_TEXT, value + value1);
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email:"));
}
}});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}});
return alert.create();
}
}
我正在检查setPositiveButton的条件。但在检查条件后,警报框会自动关闭。我希望在该过程完成之前显示警报框。我已经实现了很多东西,但无法找到解决方案。