我在 LinearLayout 中有两个 ImageView、一个文本字段和一个 WebView。我的 ImageView 侦听器不工作。这是我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_main"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="back"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/back_icon" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:clickable="true"
android:contentDescription="forward"
android:src="@drawable/back_icon"/>
<EditText
android:id="@+id/adressBar"
android:imeOptions="actionDone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ems="10" >
</EditText>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
这是我的Java代码。我应该指出 Log.d 语句没有触发,所以它肯定不会被调用:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (savedInstanceState == null) {
L.d(">>onCreateView", "savedInstanceState null");
}
View v = inflater.inflate(R.layout.browser,null);
mWebView = (WebView) v.findViewById(R.id.webView);
back =(ImageView) v.findViewById(R.id.imageView1);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("backkkkkkkkkkkkkkkk", "msg");
}
});
return v;
}