2016-05-16 8 views
2

Ich habe dieses Stück Code:Dialogtext Android ändern

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

Was soll ich tun, um die Nachricht Parameter zu erhalten, und diese Nachricht aus dem XML-Layout des Dialogfelds in einem Text setzen. Ich habe es versucht:

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

Aber es funktioniert nicht. Irgendwelche Ideen? Danke!

Antwort

1

Ersetzen Sie diese

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

Mit

TextView confirmationTextView = (TextView) deleteDialogView .findViewById(R.id.order_summary_text_view); 
+0

Sie vote up sowie genügend Abstimmung vote up :) haben –

0

Ändern von this ->

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