On Apr 3, 4:29 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I'm working on a custom html browser using WebView.loadData().  I'm
> trying to implement a back button feature, but it seems that loadData
> doesn't update the history, and I have no way to do it myself.
>
> private WebView wv;
> private boolean goBack = false;
>
> public void onCreate(Bundle icicle)
> {
>   super.onCreate(icicle);
>   wv = (WebView)findViewById(R.id.record_html);
>
>   wv.setOnKeyListener(this);
>   wv.loadData("<html><body>Test!</body></html>", "text/html",
> "utf-8");
>
> }
>
> boolean onKey(View v, int keyCode, KeyEvent event)
> {
>   if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() ==
> KeyEvent.ACTION_DOWN)
>   {
>     if (goBack)
>     {
>       if (wv.canGoBack())
>       {
>         wv.goBack();
>         goBack = !goBack;
>         return true;
>       }
>     }
>     else
>     {
>       goBack = !goBack;
>       wv.loadData("<html><body>Test 2!</body></html>","text/html",
> "utf-8");
>       return true;
>     }
>   }
>   return false;
>
> }
>
> I would expect this to first load "Test!".  When I press the back
> button, it loads "Test2!" (this part works), and sets goBack to true.
> Then I press the back button again, and it sees that it can goBack,
> and loads "Test!" again.  Instead, canGoBack() returns false.
>
> I've tried adding a WebViewClient and calling doUpdateVisitedHistory,
> but that is asking for a URL and doesn't accept data.
>
> Is there another way of doing this, or am I going to have to create a
> list of HTML to cycle through?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to