I have been looking a lot for examples on how to correctly extend AlertDialogs and get the expected behaviour, but I can hardly find any.
The docs on google doesnt r
There are few options to create custom AlertDialog. I just would like to give you answer for current question. You can set title, message and other components of AlertDialog in onCreate() method. But make sure you doing it before you calling super.onCreate() Example:
public class PausDialog extends AlertDialog {
@Override
protected void onCreate(Bundle savedInstanceState) {
View content = LayoutInflater.from(getContext()).inflate(R.layout.dialog_some_view, null);
setView(content);
setTitle("Some Title");
setMessage("Some Message");
setButton(DialogInterface.BUTTON_POSITIVE, "Ok", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d("TAG", "BUTTON_POSITIVE");
}
});
((TextView) content.findViewById(R.id.data)).setText(R.string.some_custom_data);
((TextView) content.findViewById(R.id.description)).setText(getContext().getString(R.string.description));
setCancelable(false);
setOnKeyListener((dialog, keyCode, event) -> keyCode == KeyEvent.KEYCODE_BACK);
super.onCreate(savedInstanceState);
}
}