Reputation: 51
It's my first Andoid app. I can't implement a multiple choise in my ListView(i want a checkbox in every row in my listview). I'm using the notepadv3 tutorial. Can someone help me, i'm a newbie in 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"/>
Upvotes: 2
Views: 667
Reputation: 8815
This thread in SO shows you how to display a CheckBox
and TextView
in each row of ListView
and how to bind them to the database:
Android: Binding data from a database to a CheckBox in a ListView?
You might want to have a look.
Upvotes: 0
Reputation: 30825
You need to include the checkbox in the xml layout R.layout.notes_row. If you post your xml code we might be able to help you more.
Upvotes: 1