android - 连接 2 列 Android SQLite

标签 android sqlite

到目前为止我有这个:

    Cursor cursor = dbHelper.getAllPatients();
    String[] data = new String[]{DBHelper.KEY_LNAME, 
            DBHelper.KEY_FNAME, DBHelper.KEY_DIAGNOSIS};

    int[] to = new int[] {R.id.fullname, R.id.diagnosis};

    dataAdapter = new SimpleCursorAdapter(this, R.layout.custom_row, cursor, data, to, 0);
    dbHelper.close();

    lv.setAdapter(dataAdapter);
    lv.setTextFilterEnabled(true);

getAllPatients() 方法

  public Cursor getAllPatients()
{
    Cursor localCursor = 
            this.myDataBase.query(DB_TABLE, new String[] { 
                    KEY_ID, KEY_FNAME, KEY_LNAME, KEY_DIAGNOSIS }, null, null, null, null, null);
    if (localCursor != null)
      localCursor.moveToFirst();
    return localCursor;
}

我希望列 FNAMELNAME 成为一体,但我很困惑如何以及在哪里放置连接运算符 +在字符串数组中。你有什么想法吗?我很乐意感谢你的帮助。谢谢。

最佳答案

查询时做如下操作

Cursor localCursor = 
        this.myDataBase.query(DB_TABLE, new String[] { 
                KEY_ID, KEY_FNAME +"||"+ KEY_LNAME, KEY_DIAGNOSIS }, null, null, null, null, null);

在使用您的适配器分配值时,请执行以下操作,

String[] data = new String[]{DBHelper.KEY_LNAME +"||"+ DBHelper.KEY_FNAME, DBHelper.KEY_DIAGNOSIS};

int[] to = new int[] {R.id.fullname, R.id.diagnosis};

关于android - 连接 2 列 Android SQLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17525077/

相关文章:

excel - 如何在一个单元格中获取一大段文本并插入回车以将其分解为多个单元格?

离线时 Android 缓存只读 REST API 响应

java - TCPSocket 服务在设备 sleep 模式下停止

android - Xamarin RecyclerView Click 事件获取多个上下文

android - facebook 和 google 是否有共同的 sso?

python - 插入在带有 Python 的 Sqlite 中不起作用

android - Android记事本教程中存储SQLite数据库

iOS应用程序-本地html的存储方法

android - 如何判断设备是否正在休眠

android - 以编程方式使用密码保护访问电话的设置?