After the completion of the Notepad tutorials I’ve managed to add a rating bar in the edit note section, allowing the user to interact with it and rate the note,this being saved in the SQL database. Now I’m trying to add the rating bar in the fillData() method which defines the row elements of the list allowing to easily populate the list with entries from the database. But the problem is that the program crahses because of the R.id.rating and I don’t know how to fix it. Is there a way to display the rating along with the notes in the primary list view? Thank You
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list
String[] from = new String[]{NotesDbAdapter.KEY_TITLE,NotesDbAdapter.KEY_BODY,NotesDbAdapter.KEY_RATING};
// and an array of the fields we want to bind those fields to
int[] to = new int[]{R.id.text1,R.id.text2,R.id.rating};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
setListAdapter(notes);
}
SimpleCursorAdapteronly supportsTextViewsandImageViewsand does not supportRatingBarRefer for details:
http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html
Now to display
RatingBarinListView, you have to useCursorAdapterand use itsnewViewto create andbindViewto set the rating value. You can also useListAdapterwhich is more verbose to use.Refer to:
http://developer.android.com/reference/android/widget/CursorAdapter.html
http://developer.android.com/reference/android/widget/ListAdapter.html