【问题标题】:Android ListView Not selectable anymore?Android ListView 不再可选择?
【发布时间】:2010-09-02 01:35:38
【问题描述】:

当我在 ListView 行中使用 ImageButton 时,ros 是不可选择的。当我将其更改为 ImageView 时,它是可选的。

我有这个简单的行布局,下面是我的列表,我错过了一些简单的东西吗?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:orientation="horizontal"
android:id="@+id/layoutrowtop">

    <ImageButton android:id="@+id/imgDetailDisclosure" 
    android:layout_height="fill_parent" 
    android:layout_width="48dip" 
    android:layout_gravity="center_vertical"
    android:background="#00000000">
    </ImageButton>

    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip">

                <TextView android:id="@+id/firstLine" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:ellipsize="marquee"
                android:textStyle="bold"
                android:textSize="18dp"
                android:singleLine="true"
                android:gravity="top"
                ></TextView>

                <TextView android:id="@+id/secondLine" 
                android:layout_height="fill_parent" 
                android:layout_below="@+id/firstLine" 
                android:layout_width="wrap_content"
                android:ellipsize="marquee"
                android:textStyle="italic"
                android:textSize="14dp"
                android:singleLine="false"
                android:gravity="top"
                android:lines="2"></TextView>
    </RelativeLayout>
</LinearLayout>

<LinearLayout  
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_width="fill_parent">
<EditText  
    android:id="@+id/search_box"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:hint="type to filter"
    android:inputType="text"/>

<ImageButton 
    android:id="@+id/search_button"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:src="@drawable/icon_mag_glass"/>

</LinearLayout>

<!-- Set height to 0, and let the weight param expand it -->
<!-- Note the use of the default ID! This lets us use a ListActivity still! -->
<ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1" />

【问题讨论】:

    标签: android layout


    【解决方案1】:

    您向 ListView 添加了一个可聚焦的对象(ImageButton),这使得 ListView 项目无法聚焦。有关更多详细信息和选项,请参阅相关问题:TextView and Button in each row and onListItemClick()

    【讨论】:

      猜你喜欢
      • 2011-10-28
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多