我正在尝试根据条件显示另一个警告框,但我没有得到解决方案,这是我的代码:
AlertDialog.Builder B = new AlertDialog.Builder(this);
final AlertDialog dialogue = B.create();
B.setTitle("Welcome !");
B.setMessage("Please enter a number :");
// Set an EditText view to get user input
final EditText input = new EditText(this);
input.setRawInputType(InputType.TYPE_CLASS_NUMBER);
B.setView(input);
B.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if(input.getText().toString().trim().length()==0)
{
dialogue.dismiss();
final AlertDialog.Builder Be = new AlertDialog.Builder(this);
Be.setTitle("Error !");
Be.setMessage("Please enter a valid number !");
Be.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
inal AlertDialog dialogue2 = Be.create();
dialogue2.dismiss();
dialogue.show();}
});
}
else
{//Do some stuff}
});
B.show();
}
答案 0 :(得分:0)
this 引用上一个Dialog上下文,更改它并使用活动一。
PS:我会改变它并寻找一种不同的方法,对话框内的对话框有点乱。查看EditTexts http://developer.android.com/reference/android/widget/TextView.html#setError
的.setError