У меня есть DialogFragment с настраиваемым представлением, которое содержит два текстовых поля, в которых пользователь должен ввести свое имя пользователя и пароль. Когда нажата положительная кнопка, я хочу подтвердить, что пользователь действительно ввел что-то, прежде чем отклонять диалог.
public class AuthenticationDialog extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.authentication_dialog, null))
.setPositiveButton(getResources().getString(R.string.login), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO
}
})
.setNegativeButton(getResources().getString(R.string.reset), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO
}
});
return builder.create();
}
}
Итак, как я могу предотвратить отклонение диалога? Есть ли способ, которым я должен переопределить?