2

LinearLayout に 2 つの ImageView、1 つのテキスト フィールド、1 つの 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;
}
4

5 に答える 5

0

次のようにビューを膨らませる必要があります

v = inflater.inflate(R.layout.browser, container, false);
back =(ImageView) v.findViewById(R.id.imageView1);
back.setOnClickListener(new View.OnClickListener())
{
..
}
于 2013-06-03T12:50:17.173 に答える
0

xml ファイル内のすべてのビューに対して focusable false に設定します。またはフラグメントの onActivityCreated() メソッドの imageview の setOnClickListener 。

于 2013-06-03T14:03:04.393 に答える
0

これを試して-

back.setOnClickListener(this);

onclicklistener を実装します。

于 2013-06-03T12:51:25.323 に答える