I have to show an animation when go back to previous fragment, so I must use a onBackPressed method. Since it's avaible just in activities, I tried to use a reference:
@Override
onBackPressed(){
super.onBackPressed();
infoFragment.onBackButtonPressed();
}
And in the InfoFragment I defined onBackButtonPressed method but it didn't work. So I tried like this:
view.setFocusableInTouchMode(true);
view.requestFocus();
view.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if(i==KeyEvent.KEYCODE_BACK){
MainActivity mainActivity=(MainActivity)getActivity();
mainActivity.loadMainFragment();
return true;
}
return false;
}
});
So, why it didn't work?