1

私は、リストビューを持つアプリケーションに取り組んでいます。これは、ボタンとテキストビューを内部に持つカスタムリストビューです。このリストビューには、テキストビューとボタンが含まれています。ボタンで Onclick リスナーを使用したので、 Listview で onItemClick リスナーを使用できません。それを実装するにはどうすればよいですか。

ここにコードがあります

<ListView
        android:id="@+id/lvMenuItem"
        android:layout_width="350dp"
        android:dividerHeight="3dp"
        android:layout_height="wrap_content" >
    </ListView>

LvItem.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="65dp"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imgMenu"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:clickable="false"
        android:contentDescription="@string/app_name"/>

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="wrap_content" 
        android:layout_marginLeft="5dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tvSubMenu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="" />

        <TextView
            android:id="@+id/tvType"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="" />
        <TextView
        android:id="@+id/tvPrice"
        android:layout_width="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_height="wrap_content"
        android:text="" />
    </LinearLayout>

    <Button
        android:id="@+id/btnOrder"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/btnOrder" />

</LinearLayout>

ボタンの OnclickListner が正常に動作しています。私を導いてください

ここに画像の説明を入力

4

1 に答える 1

1

フォーカス不可にするだけで、コールバックと同様Buttonに受け取ることができますButton.OnClickListView.OnItemClick

<Button
    android:id="@+id/btnOrder"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/btnOrder"
    android:focusable="false"
    android:focusableInTouchMode="false"/>

詳細については、こちらを参照してください。

于 2013-03-08T11:58:03.203 に答える