Несколько URL в одном WebView - PullRequest
0 голосов
/ 15 мая 2018

Я хочу сделать две кнопки и один WebView, но каким-то образом мое приложение останавливается.Я не могу найти ошибку.Может ли кто-нибудь помочь мне?

Main 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);
}

Может быть, кто-то может мне помочь?Я думаю, что я попробовал все.

1 Ответ

0 голосов
/ 15 мая 2018
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);
    }  
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...