开发者

How to display only some part of the data from DB into a list view

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

private void fillData() {

    Cursor c = viewDB.fetch开发者_运维百科AllRows();
    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.


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>


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....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜