3

我正在使用动态 tabhost 创建应用程序,每个选项卡都有使用以下教程的动态 webview,

http://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

4

1 回答 1

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,

用户类.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;
}

这对我有用...

于 2012-09-07T03:57:52.577 回答