HI can anybody provide me help in storing checkbox values inside a sqlite table? This is something that i tried but its not helpful. Here is the my code provide me some links or guide me how can i get what i want .Thanks in advance
db=openOrCreateDatabase("StDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS st(sms boolean,call boolean);");
addListenerOnCheck1();
addListenerOnCheck2();
}
private void addListenerOnCheck2() {
// TODO Auto-generated method stub
final Button b1=(Button) findViewById(R.id.button1);
chk1 = (CheckBox) findViewById(R.id.checkBox1);
chk2 = (CheckBox) findViewById(R.id.checkBox2);
chk1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Cursor c=db.rawQuery("SELECT * FROM st", null);
StringBuffer result = new StringBuffer();
result.append("Call ").append(chk1.isChecked());
db.execSQL("UPDATE st SET sms='"+chk1.getText()+"'");
result.append("SMS ").append(chk2.isChecked());
db.execSQL("UPDATE st SET call='"+chk2.getText()+"'");
Toast.makeText(MainActivity.this, result.toString(), Toast.LENGTH_LONG).show();
}
});
}
private void addListenerOnCheck1() {
// TODO Auto-generated method stub
chk1 = (CheckBox) findViewById(R.id.checkBox1);
chk2 = (CheckBox) findViewById(R.id.checkBox2);
chk2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
result.append("SMS ").append
(chk1.isChecked());
db.execSQL("UPDATE st SET call='"+chk2.getText()+"'");
result.append("\nCALL").append
(chk2.isChecked());
db.execSQL("UPDATE st SET sms='"+chk1.getText()+"'");
Toast.makeText(MainActivity.this, result.toString(),
Toast.LENGTH_LONG).show();
}
});
}
**
Aucun commentaire:
Enregistrer un commentaire