I have 5 fragments and every fragment has three dots in top right corner which allows user to go to another child fragment. When user enter that fragment I want to allow them to go back to fragment they were before using back button arrow in right corner. I know if I had activities instead of fragments I could just do it in Android Manifest. I don't know if it is possible to call onClick() method on back arrow button because I created it through code so it does not have an id to select it.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setHasOptionsMenu(true);
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
View rootView = inflater.inflate(R.layout.fragment1, container, false);
return rootView;
}