嗨,我创建了表格来插入记录,即名称、消息和时间。我插入成功,但如何检索插入的数据以显示在另一个活动中。这是代码。
//this i have done in Activity A:
ContentValues userValues = new ContentValues();
//name of customer
userValues.put("from_user", Application.returnEmptyStringIfNull(userName));
userValues.put(Constants.LAST_MSG, msgBody);
userValues.put(Constants.CHAT_TIME, msgTime);
if(AAEDatabaseHelper.checkIDStatus(msgTo, Constants.TABLE_LIVE_CHAT, Constants.CUSTOEMR_ID)){
String whereClause = Constants.CUSTOEMR_ID + "='" + msgTo
+ "'";
AAEDatabaseHelper.updateValues(Constants.TABLE_LIVE_CHAT,
userValues, whereClause);
}
else {
userValues.put(Constants.CUSTOEMR_ID, msgTo);
AAEDatabaseHelper.insertValues(Constants.TABLE_LIVE_CHAT,
userValues);
}
AAE数据库助手:
private static final String TEXT_NOT_NULL = " text not null ",
TEXT = " text , ", TEXT_PRIMARY_KEY = " text primary key",
CREATE_TABLE_STRING = "create table if not exists ";
private static final String CREATE_TABLE_LIVE_CHATS= CREATE_TABLE_STRING
+ Constants.TABLE_LIVE_CHAT + "(" + Constants.CUSTOEMR_ID + TEXT_PRIMARY_KEY + " , " + CHAT_COLUMN_FROM_USER_NAME
+ TEXT + Constants.CHAT_TIME + TEXT + Constants.LAST_MSG +" text ) ";
public static boolean checkIDStatus(String id, String tableName,String columnName) {
LogMessage.d("TABLE_NAME", tableName);
Cursor cursor = null;
cursor = dbHelper.query(tableName, null, columnName + "=?",
new String[] { id }, null, null, null);
boolean status = false;
try {
if (cursor != null) {
if (cursor.getCount() > 0)
status = true;
cursor.close();
}
} catch (Exception e) {
LogMessage.e(Constants.TAG, e);
}
return status;
}
In another Activity B: // 如何检索插入的数据以显示在文本中。插入的数据是用户名、消息、时间.customerid。