フラグメント内に Web ビューがあり、リンクをクリックすると次のページに移動しますが、戻るボタンをクリックしても前のページに戻りません。canGoBack を調べると、常に false です。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
gameDetailsActivity = (GameDetailsActivity)getActivity();
Bundle args = getArguments();
int type = args.getInt(ARG_OBJECT);
View rootView = null;
rootView = inflater.inflate(R.layout.gamedetailswebview,
container, false);
wv = (WebView) rootView.findViewById(R.id.WebViewGameDetails);
wv.setWebViewClient(new WebViewClient());
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setSupportZoom(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setDomStorageEnabled(true);
switch (type)
{
case 1:
wv.loadUrl(gameDetailsActivity.gameSummaryURL);
break;
case 2:
wv.loadUrl(gameDetailsActivity.gameReportURL);
break;
}
return rootView;
}
public boolean GoBack()
{
if (wv.canGoBack())
{
wv.goBack();
return true;
}
return false;
}
@Override
public void onBackPressed()
{
int currentFragmentIndex = gameDetailsViewPager.getCurrentItem();
if (currentFragmentIndex > 0)
{
Fragment webview = gameDetailsPagerAdapter
.getItem(currentFragmentIndex);
if (webview instanceof GameDetailsWebViewFragment)
{
if (!((GameDetailsWebViewFragment) webview).GoBack())
{
super.onBackPressed();
}
}
}
}