I want to disable the back button in a fragment class. onBackPressed()
doesn't seem to work in this fragment. How could I disable the back button?
This is my sample code:
public class Login extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
,Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.login, null);
return root;
}
public void onBackPressed() {
}
}
In your oncreateView() method you need to write this code and in KEYCODE_BACk return should true then it will stop the back button option for particular fragment
I know it's too late, In fragment onCreate
Change
to
OR
In your parent Activity
You have to override onBackPressed of parent FragmentActivity class. Therefore, put your codes in parent FragmentActivity. Or you can call parent's method by using this:
in FragmentActivity override onBackPressed Method and not call its super class to disable back button.