2

I want to do that: navigate the three web pages by following Button in the same activity

   mWebView = (WebView) findViewById(R.id.webView1);
   Button b1 = (Button) findViewById(R.id.button1);
   Button b2 = (Button) findViewById(R.id.button2);
   mWebView.getSettings().setJavaScriptEnabled(true);
   mWebView.loadUrl("file:///android_asset/j.html");
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
Mona Ahmad
  • 33
  • 6

2 Answers2

0

Try like :

main_activity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" />
</LinearLayout>

MainActivity.java Code For the webView.

WebView myWebView = (WebView) findViewById(R.id.webView2);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("http://www.facebook.com");

    WebView myWebView1 = (WebView) findViewById(R.id.webView);
    myWebView1.setWebViewClient(new WebViewClient());
    myWebView1.loadUrl("http://www.google.com");
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
  • thank you so much >> but how can use button to go to the next htmlpages – Mona Ahmad Mar 29 '16 at 10:47
  • button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub} //what can I put here to go to the next page? – Mona Ahmad Mar 29 '16 at 10:48
  • Please check [this SO](http://stackoverflow.com/questions/25420581/handle-onclick-function-of-html-webview-in-android) and [developer site](http://developer.android.com/intl/es/guide/webapps/webview.html#BindingJavaScript) for click event in webview – Amit Vaghela Mar 29 '16 at 11:00
0
  Button b1 = (Button) findViewById(R.id.button1);
  Button b2 = (Button) findViewById(R.id.button2);
  b1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      mWebView.loadUrl("url");
      }
  });
  b2.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
           mWebView.loadUrl("url");
      }
  });
V.Sch
  • 1,078
  • 8
  • 11