SQLiteDatabase 如何在 SQLiteDatabase 查询和 SimpleCursorAdapter 中连接两个字符串?
表字段:
_id、街道、house_nr
查询:
mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_STREET_NAME,
KEY_HOUSE_NUMBER}, null, null, null, null, KEY_ROWID + " DESC");
SimpleCursorAdapter:
Cursor c = mDbHelper.fetchAllRows();
startManagingCursor(c);
String[] from = new String[] { HistoryDbAdapter.KEY_STREET_NAME};
int[] to = new int[] { R.id.text1 };
SimpleCursorAdapter entries =
new SimpleCursorAdapter(this, R.layout.history_row, c, from, to);
setListAdapter(entries);
如何将两个数据库字段中的一个组合字符串添加到 R.id.text1 中显示完整地址。
示例:
street = "Android street"
house_nr = "911"
然后:
R.id.text1 = "Android street 911"
谢谢
Table fields:
_id, street, house_nr
query:
mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_STREET_NAME,
KEY_HOUSE_NUMBER}, null, null, null, null, KEY_ROWID + " DESC");
SimpleCursorAdapter:
Cursor c = mDbHelper.fetchAllRows();
startManagingCursor(c);
String[] from = new String[] { HistoryDbAdapter.KEY_STREET_NAME};
int[] to = new int[] { R.id.text1 };
SimpleCursorAdapter entries =
new SimpleCursorAdapter(this, R.layout.history_row, c, from, to);
setListAdapter(entries);
How to add one combined string from two db fields into R.id.text1 to show full address.
example:
street = "Android street"
house_nr = "911"
then:
R.id.text1 = "Android street 911"
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种方法:
连接查询中的两个列名称:KEY_STREET_NAME + " || " + KEY_HOUSE_NUMBER。然后我将使用 rawQuery。
使用自定义适配器。
There are two ways:
Concat both column names in the query: KEY_STREET_NAME + " || " + KEY_HOUSE_NUMBER. I would use a rawQuery then.
Use a custom adapter.
它有效:
那是我第一次。也许可以写得更简单一些?也许有任何速度建议?
It works:
Thats my first time. Maybe it can be writed more simple? maybe any speed suggestions?