public void sendMensage(Mensagem m) { ContentValues values = new ContentValues(); values.put("id_send", m.getId_send()); values.put("id_receiver", m.getId_receiver()); values.put("conteudo", m.getContent()); conn.insertOrThrow("mensagem", null, values); }
public ArrayList findMensagesByIdReceiver(int id_receiver) { String[] data = new String[] {"" + id_receiver, "" + id_receiver}; Cursor cursor = conn.query( "mensagem", null, "id_receiver = ? or id_send = ?", data, null, null, "dataEnviada"); // Cursor cursor = conn.query("mensagem", null, null, null, null, null, "dataEnviada"); ArrayList<Mensagem> results = new ArrayList<Mensagem>(); Mensagem m; if (cursor.getCount() > 0) { cursor.moveToFirst(); do { m = new Mensagem(); m.set_id(cursor.getInt(0)); m.setId_send(cursor.getInt(1)); m.setId_receiver(cursor.getInt(2)); m.setContent(cursor.getString(3)); m.setDateOfSend(cursor.getString(4)); m.setNameReceiver(this.findNameReceiver(cursor.getInt(2))); m.setNameSender(this.findNameSender(cursor.getInt(1))); results.add(m); } while (cursor.moveToNext()); } return (results); }