【问题标题】:How to add CheckBox to any ListView item in android?如何将 CheckBox 添加到 android 中的任何 ListView 项?
【发布时间】:2016-05-17 15:01:38
【问题描述】:

我正在编写一个具有 ListView 布局的应用程序,我想添加到任何行 在此 ListView 复选框中。 我该怎么做?

这是我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">
       <ListView
               android:id="@+id/listView"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:layout_weight="1">
       </ListView>
</LinearLayout>

谢谢 莫希克。

【问题讨论】:

    标签: android listview checkbox


    【解决方案1】:

    您可以使用 BaseAdapter。你可以看到一个例子here。您几乎可以在列表项中添加任何内容。您可以通过覆盖 BaseAdapter 的 getView 方法来做到这一点。您可以创建视图并以编程方式添加 CheckBox,也可以使用 xml 资源文件和 LayoutInflater。在链接的示例中使用了后一种技术。

    【讨论】:

      猜你喜欢
      • 2020-06-27
      • 1970-01-01
      • 2012-07-10
      • 2013-10-28
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 2017-12-31
      相关资源
      最近更新 更多