简体   繁体   English

CardView 复选框空白空间

[英]CardView CheckBox Empty Space

I am making a very simple Android app using Kotlin that has a checkbox list.我正在使用带有复选框列表的 Kotlin 制作一个非常简单的 Android 应用程序。 The checkbox only works when I click on the box itself or the text beside it.该复选框仅在我单击框本身或其旁边的文本时才有效。 My question is: How do I check the boxes by clicking on the empty spaces next to the texts?我的问题是:如何通过单击文本旁边的空白来选中这些框?

How to check boxes by clicking the empty space?如何通过单击空白区域来选中复选框?

Give your CardView an id attribute in your XML.在您的 XML 中为您的 CardView 提供一个id属性。

Then you can do something like this in your Activity or Fragment:然后你可以在你的 Activity 或 Fragment 中做这样的事情:

findViewById<CardView>(R.id.card_view).setOnClickListener {
    val checkBox = findViewById<CheckBox>(R.id.checkbox)
    checkBox.isChecked = !checkBox.isChecked
}

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

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