我有这段代码:
private void displayMessage(String message)
{
LayoutInflater factory = LayoutInflater.from(this);
final View deleteDialogView = factory.inflate(R.layout.dialog_confirmation, null);
final AlertDialog deleteDialog = new AlertDialog.Builder(this).create();
deleteDialog.setView(deleteDialogView);
deleteDialogView.findViewById(R.id.dialog_btn_yes).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//your business logic
deleteDialog.dismiss();
finish();
}
});
deleteDialogView.findViewById(R.id.dialog_btn_no).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteDialog.dismiss();
}
});
deleteDialog.show();
}
我想要做的是获取message参数,并将此消息从对话框的XML布局放入TextBox中。我试过这个:
TextView confirmationTextView = (TextView) findViewById(R.id.order_summary_text_view);
confirmationTextView.setText(message);
但它不起作用。有任何想法吗? 谢谢!
答案 0 :(得分:1)
替换此
TextView confirmationTextView = (TextView) findViewById(R.id.order_summary_text_view);
用
TextView confirmationTextView = (TextView) deleteDialogView .findViewById(R.id.order_summary_text_view);
答案 1 :(得分:0)
由此改变 - >
LayoutInflater factory = LayoutInflater.from(this);
final View deleteDialogView = factory.inflate(R.layout.dialog_confirmation, null);
TextView confirmationTextView = (TextView) deleteDialogView.findViewById(R.id.order_summary_text_view);
confirmationTextView.setText(message);
final AlertDialog deleteDialog = new AlertDialog.Builder(this).create();
deleteDialog.setView(deleteDialogView);