Reputation: 1729
I want to open 5 web views with an OnClickListener
button
but I want to do it in a single webView implementation
without using separate webView activities for each button.
Upvotes: 0
Views: 1656
Reputation: 2178
It's quite easy to implement:
Start with your onClickListeners, use the "URL" key or anything you like as long as they are the same everywhere and put your url as value:
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent webviewIntent = new Intent(MyActivity.this,MyWebViewActivity.class);
webviewIntent.putExtra("URL","http://www.google.com");
startActivity(webviewIntent);
}
});
In your MyWebViewActivity you can get that value in the onCreate and load that url.
String url = getIntent().getStringExtra("URL");
mWebView.loadUrl(url);
Upvotes: 2