机器人:显示HTML页面时,单击按钮? [英] android: display html pages when button clicked?

查看:436
本文介绍了机器人:显示HTML页面时,单击按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全面更新:

我有100个html文件。我知道如何初始化< web视图/> 单XML页面。但是,如果我用这个方法,那么我需要创建100 XML页面。因此,它浪费时间。

I have 100 html files. I know how to initialize the <WebView /> for single xml page. But, If I used this method, then i need to create 100 xml pages. So, its waste of time.

所以,我创建&LT;的WebView&GT; web.java 键,100键的 chapters.java

So, I created <WebView> in web.java and 100 buttons in chapters.java

我所问的是,如果按钮1 pressed, chapter1.html 应该是开放 web.java 。如果按钮2 pressed, chapter2.html 应该在 web.java <开放/ code>。像所有的100个文件应该在 web.java

What i am asking is, if button1 pressed, chapter1.html should be open in web.java. if button2 pressed, chapter2.html should be open in web.java. like all 100 files should be open in web.java ?

我的XML code:

My XML Code:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:text="Button1"
    android:onClick="Button1"/>

.... 100的TextView

.... 100 TextView

我的Java code:

My JAVA code:

public void Button1(View v) {
WebView wv;  
wv = (WebView) findViewById(R.id.webview);  
wv.loadUrl("file:///android_asset/chapter1.html"); 
}

.... 100 OnClick方法。

.... 100 OnClick method.

推荐答案

有一个在JAVA code是错误的。只是我的code替换它。

There is a mistake in JAVA CODE. Just replace it with my code.

public void webClick(View v) 
        {
            switch(v.getId())
            {
            case R.id.button1:
                Intent intent = new Intent(this, Webview.class);
                intent.putExtra("weblink","file:///android_asset/chapter/chapter1.html");
                startActivity(intent);
                break;

.
.
.
.
            default:
            break;
            }
         }

和具有以下code创建Webview.java;

And create Webview.java with the following code;

public class Webview extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);; 
        String webLink = getIntent().getStringExtra("weblink");
        WebView wv;  
        wv = (WebView) findViewById(R.id.webview);  
        wv.loadUrl(webLink);

    }

因此​​,对于每一个电话,你们各自的html文件将在同一个浏览器中打开。 Webview.java 。希望它可以帮助你。不失败,以纪念本作的答案,如果它可以帮助你。

So, for every call, your respective html file will be opened in the same browser. Webview.java. hope, it helps you. don't fail to mark this as answer if it helps you.

这篇关于机器人:显示HTML页面时,单击按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆