8

奇妙な問題に直面しています。ボタン行を削除するときに ListView にカスタム行を追加しましたが、選択可能ですが、ボタンを追加すると行をクリックできません。以下の 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" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="77dp"
    android:layout_height="77dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="18dp"
    android:src="@drawable/company_logo" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="Idds  sdsad "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/imageView1"

    android:layout_below="@+id/textView1"
    android:textColor="#8b8989"
    android:layout_marginLeft="5dp"
    android:text="Tap to see detail"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:text="Button" />

なぜこれが起こっているのか助けてください。

4

2 に答える 2

27

カスタム行を使用しているため。

onclickListenerで を設定した後、その を設定しbuttonます。getViewfocusability false

すなわち button.setFocusable(false);

また、行のレイアウト コンテナーにも設定android:descendantFocusability="blocksDescendants"します。直接設定できますandroid:focusable="false"が、これによりボタンをクリックできなくなります。

于 2013-04-20T11:14:32.997 に答える
20

設定してみる

android:focusable="false"
android:focusableInTouchMode="false"

Buttonxmlであなたに。行にフォーカスを当てるため、Button行を選択できません。

于 2013-04-20T11:12:40.310 に答える