每次在對話框中設置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();