Excellent. You should post this fix back to the Android codebase.

Yusuf Saib
Android
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.



On Aug 6, 8:23 am, midtoad <[email protected]> wrote:
> The Hello WebView demo and documentation on the Android developer site
> (http://developer.android.com/guide/tutorials/views/hello-
> webview.html) is broken.    Here are the required fixes to get it to
> work properly:
>
> main.xml: change wrap_parent to fill_parent, like so:
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>     android:layout_width="fill_parent"
>     android:layout_height="fill_parent"
>     android:orientation="vertical">
>
>     <WebView
>         android:id="@+id/webview"
>         android:layout_width="fill_parent"
>         android:layout_height="fill_parent"
>     />
>
> </LinearLayout>
>
> ==========================================
> in HelloWebView.java, you need to add a few imports that aren't
> mentioned in the docs:
>
> import android.view.KeyEvent;
> import android.webkit.WebView;
> import android.webkit.WebViewClient;
>
> In the OnCreate method, change the following code:
> - from this: webview.setWebViewClient(new WebViewClientDemo());
> - to this: webview.setWebViewClient(new HelloWebViewClient());
>
> If you prefer, here's the complete HelloWebView.java code:
>
> ============================
> package org.example.hellowebview;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.view.KeyEvent;
> import android.webkit.WebView;
> import android.webkit.WebViewClient;
>
> public class HelloWebView extends Activity {
>         /** Called when the activity is first created. */
>         WebView webview;
>         @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>         webview = (WebView) findViewById(R.id.webview);
>         webview.setWebViewClient(new HelloWebViewClient());
>         webview.getSettings().setJavaScriptEnabled(true);
>         webview.loadUrl("http://www.google.com";);
>     }
>         private class HelloWebViewClient extends WebViewClient {
>             @Override
>             public boolean shouldOverrideUrlLoading(WebView view, String url)
> {
>                 view.loadUrl(url);
>                 return true;
>             }
>         }
>         public boolean onKeyDown(int keyCode, KeyEvent event) {
>             if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
>                 webview.goBack();
>                 return true;
>             }
>             return super.onKeyDown(keyCode, event);
>         }
>
> }
>
> =================================
>
> Hope this helps!
>
> [thanks to Mark Murphy's webkit source code 
> fromhttp://commonsware.com/Android/
> for some examples that helped me pin down the errors in Google's
> docs].
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to