I want to implement custom onBackPressed methods for all my fragments which are included in my Main activity. But I am not getting a hook when my device back is pressed. I tried to implement few stuffs available in SOF, but none of them work properly. Please Help!
I tried this in onCreateView:
rootView.setFocusableInTouchMode(true);
rootView.requestFocus();
rootView.setOnKeyListener( new OnKeyListener()
{
@Override
public boolean onKey( View v, int keyCode, KeyEvent event )
{
if( keyCode == KeyEvent.KEYCODE_BACK)
{
return true;
}
return false;
}
} );