How do I call findViewById on an AlertDialog.Builder?

The currently accepted answer does not work for me: it gives me a null TextView object. Instead, I needed to call findViewById from the View that I inflated.

AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
View v = getLayoutInflater().inflate(R.layout.view_dialog, null);
builder.setView(v);

Now, I can find the TextView by using v's findViewById:

TextView card_info = v.findViewById(R.id.view_card_info_card_num);

Later, I call builder.show() to display the AlertDialog.

I found it odd that the accepted answer did not work for me. It appears consistent with the documentation. Nevertheless, I had to approach it this way.


Create the dialog from the AlertDialog.Builder, like so:

AlertDialog alert = builder.create();

Then, from the alert, you can invoke findViewById:

TextView alertTextView = (TextView) alert.findViewById(android.R.id.message);
alertTextView.setTextSize(40);