1

当我尝试将程序的结果设置为对话框中的 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();
4

1 回答 1

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();
于 2013-02-17T18:01:32.020 回答