fauzi fauzi - 5 months ago 29
Android Question

Lingking in webview to another activity

My problem is a link that i create in webview didn't work, and then when i click it, it wont go to another Activity, so where's my error?
Help, please!!! Thank you

prknln1.loadDataWithBaseURL("file:///android_asset",Perkenalan,"text/html","utf-8",null);
prknln1.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent i;
{
if (url.equalsIgnoreCase("TabHiragana")) {
i = new Intent(getApplicationContext(), TabHiragana.class);
startActivity(i);
} else if (url.equalsIgnoreCase("TabKatakana")) {
i = new Intent(getApplicationContext(), TabKatakana.class);
startActivity(i);
} else if (url.equalsIgnoreCase("Kanji")) {
i = new Intent(getApplicationContext(), List_Kanji.class);
startActivity(i);
}
}
Log.e("URL", "URL" + url);
return true;
}
});

Answer

I think you will be checking the particular word in the url, for that you need to use contains method.

prknln1.loadDataWithBaseURL("file:///android_asset",Perkenalan,"text/html","utf-8",null);
        prknln1.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Intent i;
                {
                    if (url.contains("TabHiragana")) {
                        i = new Intent(getApplicationContext(), TabHiragana.class);
                        startActivity(i);
                    } else if (url.contains("TabKatakana")) {
                        i = new Intent(getApplicationContext(), TabKatakana.class);
                        startActivity(i);
                    } else if (url.contains("Kanji")) {
                        i = new Intent(getApplicationContext(), List_Kanji.class);
                        startActivity(i);
                    }
                }
                Log.e("URL", "URL" + url);
                return true;
            }
        });
Comments