如何$里面的ListItem得到彰显p $ pvent按钮按钮、里面、ListItem、pvent

2023-09-04 07:11:18 作者:毕业了该散了

所以,我有一个ListView控件按钮自定义列表项。当pressed,按钮显示交替绘制显示反馈给用户。然而,当我点击行,每一个按钮显示pressed状态,如果我点击了他们。

So I have custom list item with buttons for a ListView. When pressed, the button display alternate drawable to show feedback to user. However when I click on the row, every buttons show pressed state as if I have clicked on them.

我如何保存按钮,将显示STATE_ pressed?

How do I keep the button displays its original state instead of state_pressed?

布局/货品:

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingTop="10dp"
    android:descendantFocusability="blocksDescendants" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:gravity="center_vertical|left" >

        <TextView
            android:id="@+id/txtMain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            style="@style/PrimaryText" />

        <TextView
            android:id="@+id/txtSub"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            style="@style/SecondaryText" />
    </LinearLayout>

    <ImageButton
        android:id="@+id/imbResponse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:focusable="false"
        android:duplicateParentState="false"
        android:src="@drawable/response_btn" 
        android:contentDescription="@string/response"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="5dp" />
</LinearLayout> 

绘制/ response_btn.xml:

drawable/response_btn.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_focused="true" android:drawable="@drawable/res_m" />
    <item android:state_pressed="true" android:drawable="@drawable/res_m" />
    <item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/res_alt_m" />
</selector>

我试图删除state_focused和STATE_ pressed,state_focused。看来这个按钮拍摄STATE_ pressed从其父。

I have tried to remove state_focused and state_pressed, state_focused. It seems that the button take state_pressed from its parent.

推荐答案

我发现设置机器人:可点击=真正的父视图将prevent孩子观看状态被改变。

I found out that setting android:clickable="true" to the parent view will prevent child views state to be changed.

请参阅这个答案。