UPDATE: Solved! Problem was related to my Viewpager not WebView.
I\'m trying to add a \"Go Back\" function to my WebView
which is insid
I've created a simple interface:
public interface IOnBackPressed {
boolean onBackPressed();
}
in the Activity:
public class MyActivity extends Activity {
@Override public void onBackPressed() {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_container);
if (!(fragment instanceof IOnBackPressed) || !((IOnBackPressed) fragment).onBackPressed()) {
super.onBackPressed();
}
}
}
in the Fragment:
public class MyFragment extends Fragment implements IOnBackPressed {
@Override
public boolean onBackPressed() {
if (webview.canGoBack()) {
webview.goBack();
// backpress is not considered in the Activity
return true;
} else {
// activity will act normal
return false;
}
}
}