简体   繁体   中英

checkbox in custom listview android

I have a custom xml file for my listview and then I use an ArrayAdapter and overwrite the getView() function to set the values for the textviews in my listview.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/tableLayout1" xmlns:android="http://schemas.android.com/apk/res/android">    
    <TableRow android:id="@+id/tableRow1">
        <TextView android:id="@+id/Name"></TextView>
    </TableRow>
    <TableRow android:id="@+id/tableRow2">
        <TextView android:id="@+id/Hrs"></TextView>
    </TableRow>
    <TableRow android:id="@+id/tableRow3">
        <TextView android:id="@+id/Value"></TextView>
    </TableRow>
</TableLayout>

Everything works fine right now, I can select an item in the listview to go inside it and I can long tap an item to get the context menu too.

The problem is if I try to add a checkbox to the above table (I also tried to change the table to a linear layout) then I can no longer select an item from the listview and I can no longer double tap on an item, although I can click on the checkbox. I want to be able to click on the checkbox which should fire an event and also have the ability to select an item in listview and long tap on an item too.

Any help is appreciated.

It is very simple.....

IN your XML file where you have the <CheckBox> </CheckBox> put android:focusable="false"

So the end should look like this >>>

<CheckBox>...android:focusable="false"...</CheckBox>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM