我正在尝试在Android应用程序的开头创建2个Alertdialog窗口。我想要一个窗口询问用户名,第二个窗口显示用户名,但按提交按钮时我的应用程序仍然崩溃
当我想通过使用getText()。toString();通过显示(Edit Text)的值来更改名为txt的TextView时,会发生主要问题。
public void Alert () {
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, R.style.MyDialogTheme);
View v = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog0, null);
builder.setMessage("Welcome ! ");
builder.setView(v);
edt = (EditText) findViewById(R.id.edit_username);
builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Alert01();
}
})
.setCancelable(false);
AlertDialog alert = builder.create();
alert.show();
}
public void Alert01 (){
AlertDialog.Builder builder01 = new AlertDialog.Builder(MainActivity.this,R.style.MyDialogTheme);
View v01 = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog1,null);
builder01.setView(v01);
txt.setText(getinfo());
builder01.setTitle("Congratulations ! ");
AlertDialog alert = builder01.create();
alert.show();
}
public String getinfo ()
{
txt = (TextView) findViewById(R.id.text02);
String info = edt.getText().toString();
return info;
}
}