我需要的是在其中動態加載在偏好對話框即視圖中的XML佈局定義的EditText:如何獲取在對話框中動態加載(setView)的佈局的元素(findViewById)?
public class ReportBugPreference extends EditTextPreference {
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
builder.setView(LayoutInflater.from(ctx).inflate(R.layout.preference_report_bug_layout,null));
EditText edttxtBugDesc = (EditText) findViewById(R.id.bug_description_edittext); // NOT WORKING
}
}
編輯:解通過jjnFord
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
View viewBugReport = LayoutInflater.from(ctx).inflate(R.layout.preference_report_bug,null);
EditText edttxtBugDesc = (EditText) viewBugReport.findViewById(R.id.bug_description_edittext);
builder.setView(viewBugReport);
}
謝謝!解決方案根據您的建議! – 2012-04-25 10:13:29