【问题标题】:Android: SimpleCursorAdapter with ListView - Put multiple fields from DB into TextViewAndroid:带有 ListView 的 SimpleCursorAdapter - 将 DB 中的多个字段放入 TextView
【发布时间】:2014-06-29 09:10:16
【问题描述】:

我是 Android 开发的新手,所以我什至不确定这是否是最好的方法。因此,如果您对我的问题有其他方法,请随时提供建议。

我的计划很基本。我有一个包含播放器的表,除了其他字段外,该表还包含名字和姓氏。

我想在 ListView 上显示所有播放器。我使用的 SimpleCursorAdapter 允许我将一个 Databasefield 映射到一个 Textview。但我想在一个 Textview 中显示名字和姓氏。我该怎么做?

这是我得到的代码:

    String[] fromFieldNames = new String[]{
        DatabaseLayout.Player.COLUMN_FIRSTNAME,
        DatabaseLayout.Player.COLUMN_LASTNAME
    };

    int[] toViewIds = new int[]{
        R.id.txt_item_playerName,
        R.id.txt_item_playerLastName
    };

    SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.item_lv_player, cursor, fromFieldNames, toViewIds);

    ListView lvPlayer = (ListView) findViewById(R.id.lvPlayer);
    lvPlayer.setAdapter(cursorAdapter);

提前致谢, 马曾

【问题讨论】:

  • 或(更高级的解决方案)使用 CursorWrapper

标签: android listview cursor adapter


【解决方案1】:

您必须实现自己的数组适配器子类。试试这个教程:http://www.vogella.com/tutorials/AndroidListView/article.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多