Reputation: 609
I am developing a simple android app that redirects to a particular website (for instance google) upon clicking on the 'start' button in my app home page. i have set the @id of my start button as 'bStart'. What should the coding be like in the method:
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
------------------
------------------
------------------
}
});
Upvotes: 0
Views: 127
Reputation: 8645
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
WebView webview = new WebView(classname.this);
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("https://www.google.co.in/");
}
});
Upvotes: 1
Reputation: 542
What I understand is you want to open a website on click of a button. Code to open a URL is:
Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Upvotes: 1
Reputation: 3417
Uri uri = Uri.parse("http://www.yourlinkhere.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
here is the code you want.hope it will help.
Upvotes: 1
Reputation: 1479
Uri uriUrl = Uri.parse(url);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
or
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://www.google.co.uk"));
startActivity(myWebLink);
Upvotes: 1