I can not use a WebViewClient

1

You see, I have a program which has to take me to a web page: link

After adding the following in AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>

I prepare the webview in an xml file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
        android:id="@+id/Paginado"
        android:layout_width="368dp"
        android:layout_height="495dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

And I enter this code in the corresponding java file:

package com.example.pcx.lingo;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class pagina extends Activity{
    WebView browser;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.manual);

        browser=findViewById(R.id.Paginado);
        browser.setWebViewClient( new Control() );

        String cadena="<a href='https://es.wikipedia.org/wiki/Lingo_(programa_de_televisión)'/>";
        browser.loadData(cadena, "text/html", "UTF-8");
    }

    public class Control extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView browser, String url){
            browser.loadUrl( url );
            return(true);
        }
    }
}

But when executing it the program hangs. What's wrong?

    
asked by Miguel Alparez 28.02.2018 в 19:03
source

0 answers