2016-05-16 78 views
2

我有这样一段代码:更改对话框文本的Android

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

我想要做的就是得到的消息参数,并从对话框中的XML布局在TextBox把这个消息。我试过这个:

TextView confirmationTextView = (TextView) findViewById(R.id.order_summary_text_view); 
    confirmationTextView.setText(message); 

但它不起作用。有任何想法吗? 谢谢!

回答

1

替换此

TextView confirmationTextView = (TextView) findViewById(R.id.order_summary_text_view); 

随着

​​
+0

不要投票行动,以及你有足够的选票投了:) –

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