3

動的タブホストでアプリケーションを作成しています。各タブには、次のチュートリアルを使用して動的 Web ビューがあります。

http://www.pocketmagic.net/?p=1132

上記はカスタムコントロールとして作成されています(ソースコードを投稿できません)。このコントロールをメイン アクティビティで拡張しました。keydown イベントで、WebView を戻せるかどうかを確認しました。可能であれば、現在の Web ビューに以前の URL をロードする必要があります。しかし、これはworking if i have worked in the same tab。2 ページ移動して 2 番目のタブに移動し、次に最初のタブに移動した場合は、 を押し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,

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;
}

それは私のために働いています...

于 2012-09-07T03:57:52.577 に答える