Issue
I am creating application with dynamic tabhost, each tab has dynamic webview using the following tutorial,
http://www.pocketmagic.net/?p=1132
The above is created as Custom control(unable post the source code). I have extended this control with main activity. In keydown event i have checked the webview able to go back or not. If can, then it should load previous url in the current webview. But this is working if i have worked in the same tab
. If i have moved two pages and shifted to second tab and then first tab, now pressing back button Application exists
. Could you please tell me how to get the current webview to go back
.
Solution
I have solved this Issue :-)
Solution:
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;
}
That is worked for me...
Answered By - Ponmalar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.