-1

I have a requirement that in a listview for every view i have to show textviews,imageview and a checkbox . but whenever if i add a checkbox to the listview then the listview loses its natural behaviour. i.e, it will not give any feedback if we click on listview.

instead I have tried by taking images even for checkboxes also everything is ok now,but checkbox.ischecked() methods so on.. can't be applied on images.

Can some one plz help out me in this issue ...

This is the layout i am using

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
   android:background="#ffffff">


<CheckBox
android:id="@+id/chkfrnd2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_x="0px"
android:layout_y="0px"/>
<ImageView
android:id="@+id/userimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</ImageView>
<ImageView
android:id="@+id/userstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
 android:src="@drawable/statusimage"
 android:layout_gravity="center_vertical"  
>
</ImageView>
<RelativeLayout    android:layout_width="wrap_content"
  android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/widget48"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
    <TextView android:id="@+id/username"
        android:layout_gravity="center_vertical"
        android:layout_width="wrap_content"         
        android:layout_height="wrap_content" 
        android:textColor="#000000"   
        android:textStyle="bold"
        android:textSize="15dip"   
        />

    <TextView android:id="@+id/userstatusmsg"
        android:layout_gravity="center_vertical"
        android:layout_width="wrap_content"        
        android:layout_height="wrap_content"
        android:textColor="#000000"   
        android:textStyle="bold"
        android:textSize="15dip"   
        android:text="TestMobileApp" />    
        </LinearLayout>
 <ImageView
android:id="@+id/userphone"
android:src="@drawable/newphone"  
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="true"
>
</ImageView>
<TextView android:id="@+id/friendstatus"

        android:layout_width="wrap_content"        
        android:layout_height="wrap_content"
        android:textColor="#000000"   
        android:textStyle="bold"
        android:textSize="15dip"   
         />  
 </RelativeLayout>
</LinearLayout>
Adinia
  • 3,722
  • 5
  • 40
  • 58
Kumar
  • 127
  • 1
  • 4

2 Answers2

0

Another possibility:

ListView OnItemClickListener Not Responding?

Community
  • 1
  • 1
Trevor
  • 10,903
  • 5
  • 61
  • 84
0

you must set the focusable attribute to false for your checkbox:

android:focusable="false"

Your question has already been answered on StackOverflow by @MattC.

Community
  • 1
  • 1
rekaszeru
  • 19,130
  • 7
  • 59
  • 73
  • Thanks rekaszeru , +1 for help.. Your answer is really helpful –  Aug 24 '12 at 07:43
  • no problem :) You should also be aware, that some other views, like the `ImageButton` and `RatingBar` do not respond for this trick, only if you set their focusable state from java code: `view.setFocusable(false)`. – rekaszeru Aug 24 '12 at 08:24
  • Thanks for more imformation.HAve you any idea that i used checkbox in listview and when i select one checkbox other check also get selected in list –  Aug 24 '12 at 09:40
  • you probably use `findViewById` on the list, not the item's view. And since the checkboxes have the same id, all of them get selected. Didi you ask a question about this here? Please share it's link to see your source code. thanks. – rekaszeru Aug 24 '12 at 09:48
  • have you asked a question already? please ask it, and share some source code as well, so we can help you :) – rekaszeru Aug 24 '12 at 10:57