I am trying to display a DialogFragment
with a button so that when I press it, the dialogue simply disappears. It should be shown when a PlainText
has no text in it but I can not get it to be displayed. What am I doing wrong?
At the moment I have this code:
public void registerUser(View view){
TextView userText = findViewById(R.id.userText);
if(userText.getText().toString().isEmpty()){
InfoDialog infoDialog = new InfoDialog(getString(R.string.empty_userName));
infoDialog.showDialog(infoDialog);
}
}
The following is the code of my InfoDialog class
public class InfoDialog extends DialogFragment {
private String message;
public InfoDialog(){ }
public InfoDialog(String message) {
super();
this.message = message;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
//Use builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(message);
builder.setPositiveButton(R.string.accept_message, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
});
return builder.create();
}
public void showDialog(DialogFragment dialogFragment){
dialogFragment.show(getFragmentManager(), "emptyUserDialog");
}
}
As far as I understand, the onCreateDialog method is called automatically or am I wrong?
Thank you in advance. Greetings