问题描述
- 更新 AlertDialog的 TextView结果
-
每次在对话框中设置textView的结果,应用会崩溃。对话框是通过链接包含textView的xml,并且这个textView就是需要更新的。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();
解决方案
改变一下顺序可以访问View的子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();
时间: 2024-09-29 22:53:02