【问题标题】:How to display only some part of the data from DB into a list view如何仅将数据库中的部分数据显示到列表视图中
【发布时间】:2011-09-05 13:05:57
【问题描述】:

这是我将数据从数据库检索到列表视图的代码。

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 个字符的数据到列表视图。请帮帮我。

【问题讨论】:

    标签: android database listview simplecursoradapter


    【解决方案1】:

    您可以将 textView 的 maxLength 属性设置为 50。

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

    【讨论】:

    • 我想为超过 50 个字符的文本附加三个点 (...)。我怎样才能追加?
    • 我不确定,但这可能是电话相关问题。我没有在模拟器中得到三个点,所以每个手机都可以用自己的方式处理这个问题。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      • 2018-01-03
      • 1970-01-01
      相关资源
      最近更新 更多