I have a TextView in a custom layout for dialog. Its text has to be changed when the dialog is about to appear.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/final_score"
/>
java code I used to set text and show dialog is
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.its_over, null));
AlertDialog dialog = builder.create();
dialog.show();
TextView t = (TextView)findViewById(R.id.final_score);
t.setText(""+score);
i have also tried this code.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.its_over, null));
AlertDialog dialog = builder.create();
TextView t = (TextView)dialog.findViewById(R.id.final_score);
t.setText(""+score);
dialog.show();
but the app would crash when these method is called.
but if we remove
TextView t = (TextView)dialog.findViewById(R.id.final_score);
t.setText(""+score);
it does not crash.