Priya Priya - 3 years ago 145
Android Question

how to combine multiple rows into one row with same column value v1 in android

View_ID
and
MAC_QR_Code
are common in multiple rows but
Button_ID
is different. What I want when retrieving
View_ID
it should be treated as single
v1
and on Image click event view all three
Button_ID
.

Insert Query
enter image description here

public void insertData(String view_id, String button_id, String publish_topic, String subscribe_topic, byte[] image, String qr_code){
SQLiteDatabase database = getWritableDatabase();
String sql = "INSERT INTO CONFIG VALUES (NULL, ?, ?, ?, ?, ?, ?)";

SQLiteStatement statement = database.compileStatement(sql);
statement.clearBindings();

statement.bindString(1, view_id);
statement.bindString(2, button_id);
statement.bindString(3, publish_topic);
statement.bindString(4, subscribe_topic);
statement.bindBlob(5, image);
statement.bindString(6, qr_code);


statement.executeInsert();
}


Get All data from SQLite

// get all data from SQLite
Cursor cursor =sqLiteHelper.getData("SELECT * FROM CONFIG");
GetAdapter1.clear();
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String view_id = cursor.getString(1);
String button_id = cursor.getString(2);
byte[] image = cursor.getBlob(5);

GetAdapter1.add(new GetAdapter(view_id, button_id, image, id));
}

Answer Source

I am working on it quite long now I saw that in SQLite we have to use select command

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download