2011-09-05 142 views
0

这里是我的代码来检索数据从数据库到一个列表视图。如何只显示数据库的一部分数据到列表视图

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); 

} 

这是行得通的。

我的数据库中第二列下面每行都有很多数据。我怎样才能显示从第二个字段只有50个字符的数据到列表视图。请帮帮我。

回答

1

你可以只设置为从的TextView的最大长度属性附加伤害50。

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

+0

谢谢。我的问题解决了 – Santhosh

+0

我想为50个字符以上的文本添加三个点(...)。我如何追加? – Santhosh

+0

我不确定,但这可能是与手机相关的问题。我在模拟器中没有三个点,所以每个手机都可以用它们自己的方式处理这个问题。 – colegu

0

的,你需要ArrayAdapter,而不是SimpleCursorAdapter并获取从DB显示,并将其设置到适配器所需的数据....

相关问题