android - 带复选框的 ListView - 为什么复选框不显示?

标签 android listview checkbox

我正在使用 ListView 提供一个列表供用户选择。

主要代码如下:

SimpleAdapter adapter = new SimpleAdapter(this,contacts, R.layout.list_contact,
                                          from_contacts, to_contacts);
listview_selected_contact.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listview_selected_contact.setAdapter(adapter);

我想知道为什么复选框不显示? 程序在没有可见复选框的情况下正常运行。 谁能帮忙?

这是 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/username"></TextView>

</LinearLayout>

最佳答案

看起来你的 R.layout.list_contact 不是 CheckedTextView。

参见 source of android.R.layout.simple_list_item_multiple_choice

我可以建议您构建自定义 View ,它是任何 ViewGroup 类的子类和接口(interface) Checkable 的实现者。

关于android - 带复选框的 ListView - 为什么复选框不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8295560/

相关文章:

javascript - 在 Apex 表格表单中选择一系列复选框(使用 jQuery)

javascript - 使用 jquery 选中或取消选中父父复选框

android - SDK >=26 仍需要 mipmap/ic_launcher.png?

android - 如何从 ListView 中找到选中的复选框?

wpf - 数据网格,合并/组合行、单元格和列

java - 更改项目类型时 JavaFX 中的 ListView 出现 ClassCastException

安卓。如何从 Espresso 测试库中滑动 NavigationDrawer?

android - 如何在 android 中进行 robotium 测试时从项目中打开另一个项目

javascript - React native,添加 Root View 时出错

html - 复选框的 WebKit 样式在 IE 8 中不起作用