4

私のListViewでは、私のリストアイテムは以下のように表示されます

これは私のrow.xmlレイアウトです

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/Peru"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/et_back_yellow"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/ib_edit"
            android:layout_width="35dp"
            android:layout_height="30dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:background="@drawable/ib_selector"
            android:contentDescription="@string/edit"
            android:src="@drawable/edit" />

        <TextView
            android:id="@+id/tv_date"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="100"
            android:gravity="center_vertical|center_horizontal" />

        <TextView
            android:id="@+id/tv_time"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="100"
            android:gravity="center_vertical|center_horizontal" />

        <ImageButton
            android:id="@+id/ib_delete"
            android:layout_width="35dp"
            android:layout_height="30dp"
            android:layout_marginBottom="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:background="@drawable/ib_selector"
            android:contentDescription="@string/edit"
            android:src="@drawable/delete" />
    </LinearLayout>

    <EditText
        android:id="@+id/et_note"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/title"
        android:layout_alignRight="@+id/title"
        android:layout_below="@+id/title"
        android:layout_marginTop="5dp"
        android:ems="10"
        android:inputType="textMultiLine" 
        android:background="@color/yellow">

        <requestFocus />
    </EditText>

</RelativeLayout>

リスト項目をクリックすると、onListItemClick メソッドが機能しません。しかし、row.xml からボタンを削除すると機能します。誰か助けてください。よろしくお願いします。

4

3 に答える 3

8

とでこの属性を使用しLinearLayoutますRelativeLayout

android:descendantFocusability="blocksDescendants"
于 2013-02-28T15:15:02.373 に答える
0

hereに記載されているように、 との子ビューの両方onItemClickを持つことはできません。はフォーカスとクリックが有効になっているため、 は起動しません。onClickListViewButtononItemClick

于 2013-02-28T15:13:15.667 に答える
0

私が思う問題の理由は、imageButtonsに与えられたレイアウトの重みです。したがって、linearLayout 自体に weightSum 属性とともに、線形レイアウト内のすべてのビューに重みを与えてみてください。

clickListener が機能していない理由は、ImageButton が行の幅全体にラップされており、項目にリスナー コードが実行できるスペースがなくなっているためです。

于 2013-02-28T15:13:29.287 に答える