android - 如何在 ListView 的每一行中实现一个复选框

标签 android android-listview

这是我的第一个 Andoid 应用程序。我无法在我的 ListView 中实现多项选择(我希望我的 ListView 中的每一行都有一个复选框)。 我正在使用 notepadv3 教程。 有人可以帮助我吗,我是 Java 的新手。

private void fillData() {
     ListView lView = (ListView) findViewById(android.R.id.list);
    // Get all of the notes from the database and create the item list
    //lView = (ListView) findViewById(R.id.liste);
    Cursor c = mDbHelper.fetchAllNotes();
    startManagingCursor(c);
    String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
    int[] to = new int[] { R.id.text1 };
    // Now create an array adapter and set it to display using our row
    SimpleCursorAdapter notes =
        new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
    setListAdapter(notes);

<?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/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


<CheckBox android:text=""
    android:id="@+id/list_checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="false"
    />

<TextView android:id="@id/android:empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/no_notes"/>

最佳答案

您需要在 xml 布局 R.layout.notes_row 中包含复选框。如果您发布您的 xml 代码,我们也许可以为您提供更多帮助。

关于android - 如何在 ListView 的每一行中实现一个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7948914/

相关文章:

android - 自定义 ListView - 无法实例化类型 ListAdapter

android - AWS iOS/Android SDK 大小问题

java - 提高文件搜索和 MediadataRetriever 的性能

java - 调用notifyDataSetChanged 时,具有customAdapter 的ListView 未更新?

android - 使用 JSONObject 填充 Listview 内的 Listview 绑定(bind)

java - 由自定义 ArrayAdapter 中按钮的事件创建的 DialogFragment 始终具有相同的位置

android - 单击通知没有开始预期的 Activity ?

java - 无法集中动画 (libGdx)

java - setText 未在 Runnable 中更新

android - 获取所选项目值抛出 IndexOutOfBoundsException