连接2列Android SQLite

时间:2013-07-08 11:05:27

标签: 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;
}

我希望列 FNAME LNAME 成为一个但我很困惑如何以及在何处放置连接运算符 + 在String数组中。你有任何想法吗?我很乐意感谢你的帮助。感谢。

2 个答案:

答案 0 :(得分:2)

查询时执行以下操作

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

答案 1 :(得分:0)

试试这个

SELECT CONCAT(ColA, ColB) AS ColC FROM Table

String query = "select" +ColA+"+"+ColB +"as CompleteAddress from YourTable";