2011-09-05 41 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顯示,並將其設置到適配器所需的數據....

相關問題