2012-03-18 6 views
2

이미지와 일부 레이아웃이있는 텍스트가있는 목록 뷰가 만들어져 작동했습니다. 내가 클릭 할 때마다 텍스트 "onListItemClick는"성공적으로 불렸다 :체크 박스를 추가하면 목록보기에 더 이상 클릭이 발생하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 

<ImageView 
android:id="@+id/image" 
android:layout_width="40dip" 
android:layout_height="40dip" 
android:src="@drawable/icon"/> 

<TextView 
android:id="@+id/text" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/> 

</LinearLayout> 

가 그럼 난 텍스트와 이미지 사이에 체크 박스를 추가하고 내가 텍스트를 클릭하면 또한 내가 클릭하지 때 더 이상 클릭을 얻을 수있다 체크 박스 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 

<ImageView 
android:id="@+id/image" 
android:layout_width="40dip" 
android:layout_height="40dip" 
android:src="@drawable/icon"/> 

<CheckBox 
android:id="@+id/check" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content"/> 

<TextView 
android:id="@+id/text" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/> 

</LinearLayout> 

확인란과 텍스트를 클릭 할 수있는 방법이 있습니까?

+0

당신이에서와 같이'ListView'에서 클릭 이벤트를 얻으려고 노력하고있는 레이아웃 = "거짓" ,'CheckBox' 또는'TextView'가 클릭되었을 때 "onListItemClick"을 호출하기를 원합니까? 아니면 자신의 견해로 이벤트를 받고 싶습니까? – Brian

답변

4

확인란이 아마도 초점을 훔칠 것입니다.

체크 박스에 android:focusable="false"을 설정해보십시오.

사이드 노트 : 프레임 워크가 대부분의 작업을 처리하는 목록에서 체크 박스 선택을 처리하는 방법이 있습니다. 목록에 CHOICE_MODE_MULTIPLE을 설정하고 예를 들어 CheckedTextView 인 레이아웃을 사용하십시오. getCheckedItemIds()을 사용하여 ID를 가져올 수 있습니다. 예를 들어 android.R.layout.simple_list_item_multiple_choice를 참조하십시오. api 데모에는 구현이 있습니다. 클릭 목록을 올바르게 처리하지 못하므로 확장형 목록보기에서이 방법을 사용하지 마십시오.

+0

고마워요, 제가 정확히 찾고 있었던 것이 었습니다. – HardCoder

+0

그래서 어떤 아이디어를 ExpandableListView로 할 것인가? 나는 내가 선택한 "항목"을 알아야합니다. 확인란을 사용하지 않을 경우 가장 적합한 솔루션은 무엇입니까? –

1

나는 안드로이드로 설정 시도가 체크 박스의 포커스 특성과 관련이있다 생각 : 포커스

관련 문제