首页 文章

网站加载后,Webview按钮停止工作

提问于
浏览
1

我创建了一个简单的 webview ,下面有两个 buttons . 如果我按下其中一个按钮,视图似乎会创建一个名为"web"的新视图,然后页面加载,我仍然有下面的按钮,但它们不起作用 . 如果我使用手机上的后退按钮,它会将我带到打开的视图空白页面并且按钮再次工作?对不起我是新来的..

我只是想在原始视图中加载并让按钮继续运行 .

我是否必须以某种方式抑制新视图的创建?

亲切的问候,

-麦克风

**并且我不确定为什么我的代码在我发布时总是有额外的废话,因为当我将它复制到剪贴板时它不会 . **

enter image description here

Webscreen类

package com.example.cam;

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

public class Webscreen <URL> extends Activity {
    WebView webview1;

    public static final String URL = "";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String turl = getIntent().getStringExtra(URL);

        webview1 = (WebView)findViewById(R.id.webview01);

        webview1.clearCache(true);
        webview1.loadUrl(turl);
    }
}

凸轮类

package com.example.cam;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class cam extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Add Click listeners for all buttons
        View firstButton = findViewById(R.id.button1);
        firstButton.setOnClickListener(this);
        View secondButton = findViewById(R.id.button2);
        secondButton.setOnClickListener(this);
    }

    // Process the button click events
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.button1:
                Intent j = new Intent(this, Webscreen.class);
                j.putExtra(com.example.cam.Webscreen.URL, 
                    "http://m.yahoo.com");
                startActivity(j);
            break;
            case R.id.button2:
                Intent k = new Intent(this, Webscreen.class);
                k.putExtra(com.example.cam.Webscreen.URL, 
                    "http://m.google.com");
                startActivity(k);
            break;      
        }
    }
}

2 回答

  • 1

    我不知道你为什么不使用Button类并使用View Class . 使用

    Button b1=(Button)findViewById(R.id.button1);
    

    代替

    View b1=findViewById(R.id.button1);
    

    使用相对布局来放置按钮

  • 0

    在按钮上单击 you are recreating your activity 以显示网页 .

    Intent j = new Intent(this, Webscreen.class);
            j.putExtra(com.example.cam.Webscreen.URL, 
                "http://m.yahoo.com");
            startActivity(j);
    

    它只是在按钮点击时加载网页所需的新活动之上创建新活动 .

    //on button1 click 
    mWebView.loadUrl("http://m.yahoo.com");
    

相关问题