1
我很新,Java我试图让事情变得简单。为什么这不起作用?我有一个EditText
字段和Submit Button
的XML布局。我想按下它,AlertDialog
弹出我输入EditText
的TextView
。我试过的东西不断崩溃:提交EditText并在AlertDialog中显示结果TextView
//CustomAlertDialogPopUp
public void submitButton(View v) {
LayoutInflater inflater = getLayoutInflater();
View alertLayout = inflater.inflate(R.layout.alertXML, null);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Alert");
alert.setView(alertLayout);
AlertDialog dialog = alert.create();
dialog.show();
EditText text1 = (EditText)findViewById(R.id.inputText);
TextView text2 = (TextView)findViewById(R.id.alertText);
String result = text1.getText().toString();
text2.setText(result);
}
对不起,如果我听起来很愚蠢!就像我说的,超级新。
什么是logcat的输出?我们看不出它为什么会崩溃 – basic
EditText text1 =(EditText)** alertLayout **。findViewById(R.id.inputText); –