我想制作两个按钮和一个WebView,但不知怎的,我的应用程序停止了。我找不到错误。有人能帮助我吗?
主Java:
public void setButtononClick(View v) {
String url = null;
switch(v.getId()) {
case R.id.button1:
url="https://www.delfi.lt";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://delfi.lt")));
break;
case R.id.button2:
url= "https://www.youtube.com";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com")));
break;
}
Intent launchBrowser = new Intent(Intent.ACTION_VIEW );
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url)); startActivity(intent);
}}
WebView ACC JAVA
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
// Get reference of WebView from layout/webviewex.xml
webView = (WebView) findViewById(R.id.webView1);
// Get URL from Intent
String URL = getIntent().getExtras().getString("URL");
// Load website
webView.loadUrl(URL);
}
也许有人可以帮助我?我想我尝试了一切。
答案 0 :(得分:1)
public void onClick(View v) {
String url;
switch(v.getId()) {
case R.id.button1:
url="https://www.delfi.lt";
launchBrowserWithUri(Uri.parse(url))
break;
case R.id.button2:
url= "https://www.youtube.com";
launchBrowserWithUri(Uri.parse(url))
break;
}
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uri);
if (getActivity() != null && launchBrowser.resolveActivity(getActivity().getPackageManager()) != null){
startActivity(launchBrowser);
}