当我按下按钮时为什么不打开webviewer?

时间:2017-06-14 16:16:49

标签: android button webview click android-sdk-2.3

所以我有这个按钮,我希望它在按下按钮时打开一个webviewer。

这是按钮

的xml
task_id = cool_task.s(arg1, arg2).apply_async()

这里是点击按钮的类代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
    android:id="@+id/signIn"
    android:layout_width="match_parent"
    android:layout_height="61dp"
    android:src="@drawable/signin"
    android:textAlignment="center" />

</LinearLayout>

这里是我有webviwer.xml

的地方
public class SignIn extends Activity {
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    img = (ImageView) findViewById(R.id.signIn);
    signIn();

}
public void signIn() {
    img.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(SignIn.this, WebViewActivity.class);
            startActivity(intent);
        }
    });
}
}  

这是webviewer类

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/webView1"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" />  

当点击没有任何反应时,我也编辑了清单以进行互联网访问

2 个答案:

答案 0 :(得分:0)

进行小幅修正。在XML中,您使用的是“ImageButton”,但在java文件中,您使用的是“ImageView”。

<ImageView
android:id="@+id/signIn"
android:layout_width="match_parent"
android:layout_height="61dp"
android:src="@drawable/signin"
android:textAlignment="center" />

答案 1 :(得分:0)

我认为在XML ImageButton和java文件中编写以ID搜索ImageView是错误的。

使用ImageView或ImageButton!

如果您想使用imageView,请不要忘记使其成为可引用的。