当我尝试将程序的结果设置为对话框中的textView时,应用程序强制关闭。我通过链接一个带有textview的xml来创建对话框,这是我试图更新的文本视图。
AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater factory = LayoutInflater.from(this);
resultOne=(TextView)findViewById(R.id.resultOne); //resultone is a textview in xml dialog
resultOne.setText("hello"); //this code is making the app close
final View textEntryView = factory.inflate(R.layout.dialog, null);
alert.setView(textEntryView);
alert.show();
答案 0 :(得分:2)
更改订单,以便在充气后访问View的孩子。您还需要使用textEntryView
来查找ID,如下所示:
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.dialog, null);
resultOne=(TextView)textEntryView.findViewById(R.id.resultOne); //resultone is a textview in xml dialog
resultOne.setText("hello");
alert.setView(textEntryView);
alert.show();