In the Notepad example, they display a list of titles. How would you change it to display a second line with the body text in a smaller font?
Here is the relevant code:
private void fillData() {
// Get all of the rows from the database and create the item list
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1};
// 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);
}
And this is notes_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:minWidth="100dp"/>
The comments clearly state that it only displays the title. I wish it gave me some hints as to how to display the body text as well. (Let’s not discuss whether that’s a good idea. Let’s just assume that that needs to be done, because I’m trying to adapt the Notepad example to my own app.)
Simply add another textview to your row:
And change your method to the following:
Please note that it may not be NotesDbAdapter.KEY_BODY to retrieve the body column, you should be able to look in your NotesDbAdapter class, at the constant that refers to the body column name and use that.
Also – play with the font size some (android:fontSize=) … 20dp may be VERY small to the point where you can’t even see it (I haven’t tested this).