title: Show specific url in webview according to button link
body: <p>I am new to android apps development. By searching many links and reading the discussion on StackOverflow, I am able to create WebView through button link. But I can't success to use multi URL in WebView though I have tried a lot. I mean how can I <strong>show different URL in one webview according to specific button link</strong>. For example: if button 1 clicked it would show google.com, button 2 would show facebook.com etc in webview. I have coded as follow. </p>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Loading from a Webpage"
          android:layout_margin="10dp"
          android:onClick="clickweb"/&gt;
  
      &lt;Button
          android:id="@+id/button2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Loading from a Webpage"
          android:layout_margin="10dp"
          android:onClick="clickweb"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <p>public class MainActivity extends Activity {</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  }
  public void clickweb(View v) {
      Toast.makeText(MainActivity.this, "Web view selected", Toast.LENGTH_LONG).show();
      Intent i1 = new Intent(MainActivity.this,LoadWeb.class);
      startActivity(i1);
  }
  }
  </code></pre>
  
  <p><strong>LoadWeb.java</strong></p>
  
  <pre><code>@SuppressLint("SetJavaScriptEnabled")
  public class LoadWeb extends Activity {
  
  private WebView mWebView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.webviewex);
  
      // Get reference of WebView from layout/webviewex.xml
      mWebView = (WebView) findViewById(R.id.webView1);
  
      setUpWebViewDefaults(mWebView);
      // Load website
      mWebView.loadUrl("https://www.google.co.in");
  }
  
  //Convenience method to set some generic defaults for a
  
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private void setUpWebViewDefaults(WebView webView) {
      WebSettings settings = webView.getSettings();
  
      // Enable Javascript
      settings.setJavaScriptEnabled(true);
  
      // Use WideViewport and Zoom out if there is no viewport defined
      settings.setUseWideViewPort(true);
      settings.setLoadWithOverviewMode(true);
  
      // Enable pinch to zoom without the zoom buttons
      settings.setBuiltInZoomControls(true);
  
      if(Build.VERSION.SDK_INT &gt; Build.VERSION_CODES.HONEYCOMB) {
          // Hide the zoom controls for HONEYCOMB+
          settings.setDisplayZoomControls(false);
      }
  
      // Enable remote debugging via chrome://inspect
      if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
          WebView.setWebContentsDebuggingEnabled(true);
      }
  }
  }
  </code></pre>
  
  <p><strong>webviewex.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;
  
      &lt;WebView
          android:id="@+id/webView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>