I have a fragment with two buttons - confirm and cancel. One button, the confirm button, takes the user input from an EditText and convert it to an USSD request. Now I'd like to have the cancel button close that fragment like the negative button on an alertDialog.
I've read many questions a bit similar to this but none of them seems to fullfil my need.
public void onClick(View v) {
switch (v.getId()) {
case R.id.confirmButton:
if (inputField.getText().toString().trim().length() == 16) {
load();
inputField.requestFocus();
} else if (inputField.getText().toString().trim().length() < 16) {
Toast.makeText(getActivity(), R.string.toast_number_not_valid, Toast.LENGTH_SHORT).show();
}
break;
case R.id.cancelButton:
dismiss();
break;
}
}
private void load() {
// bla - bla - bla
}
public void dismiss(){
//dear fragment, I don't need you right now, just dismiss
}
Here I need the dismiss() method.
Any help will be appreciated.
Just call:
getActivity().onBackPressed();