【问题标题】:ListView with checkbox - why the checkbox doesn't show?ListView with checkbox - 为什么复选框不显示?
【发布时间】:2011-11-28 20:20:24
【问题描述】:

我正在使用 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>

【问题讨论】:

  • 我认为这是因为您提供了自己的布局。向我们展示您的 layout.xml

标签: android listview checkbox


【解决方案1】:

您的 R.layout.list_contact 似乎不是 CheckedTextView。

source of android.R.layout.simple_list_item_multiple_choice

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

【讨论】:

    【解决方案2】:

    R.layout.list_contact 中的checkBoxlistView 的id 应该是特定的。

    因此,请按照 ApiDemoes 的多个列表示例进行布局和 java 代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多