I am new to Android.
I want to display HTML pages in android emulator. I put my “test1.html” and “test2.html” files in the “assets” folder and managed to display “test1.html” file in Android by using the following code.
package com.example.helloandroid;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
setContentView(webview);
try {
InputStream fin = getAssets().open("test1.html");
byte[] buffer = new byte[fin.available()];
fin.read(buffer);
fin.close();
webview.loadData(new String(buffer), "text/html", "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Now I want to click a button or a link in the “test1.html” file and open the “test2.html” file.How can I link those two HTML pages?
Thanks in advance.
ButtonorLinkintest1.htmlshould just work like normal html file. Make sure when you provide the path fortest2.htmlis right with respect totest1.htmlsince they are in assets directory.Edit your code like this