Question

Here is my code to retriev the data from db to a listview.

private void fillData() {

    Cursor c = viewDB.fetchAllRows();
    startManagingCursor(c);

    String[] from = new String[] { ViewComplaintsDataDB.KEY_NUMBER,
            ViewComplaintsDataDB.KEY_DESCRIPTION,
            ViewComplaintsDataDB.KEY_LOGGEDBY }; //these three are the fields in my db

    int[] to = new int[] { R.id.com_num, R.id.com_desc , R.id.user }; //these three are the textview id's in my listitem.xml file 

    SimpleCursorAdapter simple = new SimpleCursorAdapter(this,
            R.layout.listitem, c, from, to);

    setListAdapter(simple);

}

This is working.

There is a lot of data in each row under the second column in my DB. How can i display only 50 characters of data from the second field to the listview. Please help me.

Was it helpful?

Solution

You could just set the maxLength atribute from the textView to 50.

<TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxLength="50"></TextView>

OTHER TIPS

for that you need to ArrayAdapter instead of SimpleCursorAdapter and fetch the data required to show from the DB and set it to the adapter....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top