这是我的第一个 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/