2013-05-09 19 views
1

我創建了一個對話框,像這樣使用自定義佈局:對話情境問題 - Android電子

dialog = new Dialog(FetchMenu.this, R.style.CustomDialogTheme); 
    dialog.setContentView(R.layout.custom_dialog_iab); 
    dialog.show(); 

現在我想「layout.custom_dialog_iab」中編輯的文本框,例如:

TextView text = (TextView) findViewById(R.id.all_topics_unlock_button); 
text.setText("Purchased"); 

我的問題:如何獲得正確的上下文以編輯文本框?

P.S.我已經嘗試'dialog.getContext()',但仍然保持拋出空指針?

+2

你有沒有嘗試過'TextView text =(TextView)對話框。 findViewById(R.id.all_topics_unlock_button);'顯示對話框後? – 2013-05-09 19:15:17

回答

3

您需要使用:

​​

注意dialog.在findViewById

定期findViewById()會搜索自己的活動佈局,而不是對話的佈局。

+0

正是我需要的感謝 – Jonno 2013-05-11 22:32:09