简体   繁体   English

自定义listview android中的复选框

[英]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文件,然后使用ArrayAdapter并覆盖getView()函数为列表视图中的文本视图设置值。

<?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" 在您的XML文件中,您将<CheckBox> </CheckBox>放入android:focusable="false"

So the end should look like this >>> 所以最后应该看起来像这样>>>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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