In the Android docs on AlertDialog, it gives the following instruction and example for setting a custom view in an AlertDialog:
If you want to display a
android.R.id.custom was returning null for me. I managed to get this to work in case anybody comes across the same issue,
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle("My title")
.setMessage("Enter password");
final FrameLayout frameView = new FrameLayout(context);
builder.setView(frameView);
final AlertDialog alertDialog = builder.create();
LayoutInflater inflater = alertDialog.getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.simple_password, frameView);
alertDialog.show();
For reference, R.layout.simple_password is :