我正在使用动态tabhost创建应用程序,每个选项卡都使用以下教程
进行动态webviewhttp://www.pocketmagic.net/?p=1132
以上是作为自定义控件创建的(无法发布源代码)。我用主要活动扩展了这个控制。在keydown活动中,我检查了webview是否可以返回。如果可以,那么它应该加载当前webview中的前一个URL。但这是working if i have worked in the same tab
。如果我移动了两个页面并转移到第二个标签然后转到第一个标签,现在按back button Application exists
。你能告诉我how to get the current webview to go back
。
答案 0 :(得分:0)
我已经解决了这个问题: - )
<强>解决方案:强>
1. Created One class named MyWebView that should extends WebView.
2. Created 4 MyWebView instances from User Side.
3. That MyWebView should have one WebView locally and it should not be static( here i did a mistake).
4. Override the Layout of WebView inside the MyWebView class with Progressbar and WebView inside the FrameLayout.
5. For every tab creation we have to set the Content as instance of MyWebView.
6. Now handle as follows,
<强> UserClass.java 强>
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(event.getAction() == KeyEvent.ACTION_DOWN)
{
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(webView1!=null)
{
currentWebView= webView1.getWebView();
if(currentWebView!=null && currentWebView.canGoBack() == true)
{
currentWebView.goBack();
}
else
//Show Alert to Quit the Application
}
else
//Show Alert to Quit the Application
return true;
}
}
}
<强> MyWebView.java 强>:
public WebView getWebView()
{
return webview;
}
这对我有用......