2014-01-06 3 views
0

ArrayAdapter을 상속하는을 가진 ListView을 받았습니다. 나는 사용자 정의 Checkable 하위 클래스 인 LinearLayout을 사용하여 목록에서 마지막으로 선택된 항목을 강조 표시하여 기본적으로 선택된 상태를 선택 항목으로 매핑합니다. 다음과 같이ImageButton이 추가 될 때 duplicateParentState가 작동하지 않습니다.

목록 항목에 대한 Adapter 사용하는 레이아웃이다 : 그것은 내가 마지막 ImageButton보기를 추가하고있어 때까지 텍스트 색상이 마지막 감동 항목에 대한 변화와 함께 예상대로 작동

<com.wordlistdictionary.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="40dp"> 
<LinearLayout 
    android:id="@+id/entry_text" 
    android:layout_width="0dp" 
    android:layout_weight="7" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:duplicateParentState="true" 
    /> 

<TextView 
    android:id="@+id/entry_number_of_occurences_1" 
    android:textSize="9pt" 
    android:typeface="monospace" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:textColor="@color/item_text_color_selector" 
    android:layout_gravity="center_vertical" 
    android:layout_weight="1" 
    android:duplicateParentState="true" 
    /> 

<TextView 
    android:id="@+id/entry_frequency_1" 
    android:textSize="9pt" 
    android:typeface="monospace" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:textColor="@color/item_text_color_selector" 
    android:layout_gravity="center_vertical" 
    android:layout_weight="2" 
    android:duplicateParentState="true"/> 

<ImageButton 
    android:id="@+id/delete_entry_button_1" 
    android:src="@drawable/delete_button_selector" 
    android:layout_height="40dp" 
    android:layout_width="40dp" 
    android:layout_gravity="center_vertical" 
    android:layout_marginRight="15dp" 
    android:duplicateParentState="true" 
    /> 
</com.wordlistdictionary.CheckableLinearLayout> 

그 지점에서 텍스트를 강조 표시하지 않습니다.

누구에게이 문제가 발생 했습니까? 해결책은 무엇입니까?

현재 레이아웃보기 자체의 선택 상태를 변경하고 duplicateParentState 메커니즘에 의존하는 대신 사용자 지정 레이아웃에서 모든 자식 뷰에 선택된 상태를 수동으로 전파하는 방법을 생각하고 있습니다. 나는 내 사용자 지정 AdaptergetView()에서 imageButton.setTouchable(false)을 설정했다 그래서 목록보기로 전파되지 않도록 목록 항목에 Button 또는 ImageButton "제비"는 감동 이벤트를 추가 할 때

답변

0

이 밝혀졌습니다.

먼저 레이아웃 파일에 android:touchable='falase'을 설정하려고했지만 프로그래밍 방식으로 설정해야하므로 작동하지 않았습니다.

나는이 2 개 개의 SO 질문에 대한 답을 발견했습니다
ListView setOnItemClickListener not working by adding button
Click is not working on the Listitem Listview android

+0

예,하여 ImageButton 이벤트가 늘 아버지에게 돌아올 수 있도록 클릭 할 수있는보기, 그것은/터치를 소비하는 이벤트를 클릭 것이다 형세. 텍스트 뷰를 클릭 가능으로 설정하면 동일한 효과가 나타납니다. – Qing

관련 문제