2013-02-17 37 views
1

當我嘗試將程序的結果設置爲對話框中的textView時,app force關閉。我通過鏈接一個帶有textview的xml來創建對話框,這是我嘗試更新的這個textview。將AlertDialog的TextView更新結果Android

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(); 

回答

2

更改順序,這樣你接取該視圖的孩子後膨脹了。您還需要使用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();