public ArrayList<Chat> fetchChatHistory(String senderId, String receiverId) {
ArrayList<Chat> chatList = new ArrayList<Chat>();
String where = "" + DataProviderConstants.MESSAGE_RECEIVER_ID_COLUMN
+ " in (?,?) AND "
+ DataProviderConstants.MESSAGE_SENDER_ID_COLUMN + " in (?,?) "
/*
* +"("+DataProviderConstants.MESSAGE_RECEIVER_ID_COLUMN+"=? AND "
* +DataProviderConstants.MESSAGE_SENDER_ID_COLUMN+"=?)"
*/;
Cursor cursor = mContext.getContentResolver().query(
DataProviderConstants.MESSAGE_TABLE_CONTENTURI, null, where,
new String[] { senderId, receiverId, senderId, receiverId },
DataProviderConstants.MESSAGE_ID_COLUMN);
if (cursor != null && cursor.moveToFirst()) {
do {
Chat chat = new Chat();
chat.setRecieverID(cursor.getString(cursor
.getColumnIndex(DataProviderConstants.MESSAGE_RECEIVER_ID_COLUMN)));
chat.setSenderID(cursor.getString(cursor
.getColumnIndex(DataProviderConstants.MESSAGE_SENDER_ID_COLUMN)));
chat.setMessage(cursor.getString(cursor
.getColumnIndex(DataProviderConstants.MSG_COLUMN)));
chat.setLat(cursor.getString(cursor
.getColumnIndex(DataProviderConstants.MESSAGE_LAT_COLUMN)));
chat.setLon(cursor.getString(cursor
.getColumnIndex(DataProviderConstants.MESSAGE_LON_COLUMN)));
int isunread = cursor.getInt(cursor
.getColumnIndex(DataProviderConstants.MSG_IS_UNREAD));
chat.setIsUnread((isunread == 0 ? false : true));
chat.setDelvired(true);
chatList.add(chat);
} while (cursor.moveToNext());
}
return chatList;
}
Using this code am able to fetch data from Sq-lite database in forward direction while i want to get in reverse Order i am using Collections.reverse but here giving Error i don't how to get data in reverse Order from Sq-lite in android there is missing Some thing please suggest me or help me .
Aucun commentaire:
Enregistrer un commentaire