2011-01-20 66 views
0

我是Android新手。我想知道如何將值從活動傳遞給自定義對話框。Android定製對話框

假設我想將活動中的文本傳遞給自定義對話框中的edittext框,那我該怎麼辦?

+0

顯示你目前擁有的代碼(如果您創建對話框) – 2011-01-20 11:51:07

回答

0
... somewhere in activity.... 
private String myValue = "hello :)"; 
... somewhere in activity when you show dialog... 
final View customView = getLayoutInflater().inflate(R.layout.custom, null); 
final EditText editTxt = customView.findViewById(R.id.edittext_in_custom_view); 
editText.setText(myValue); 
new AlertDialog.Builder(this).setView(customView).create().show(); 
....