I have an app that gets data from a sqlite db, it can do inserts fine, it then on buttonclick displays this data from the db in different objects such as edittexts, textviews and unfortunatly radio buttons.
I have 5 radiobuttons each represent one unique value in the db:
1.New 2.Good 3.Fair 4.Poor 5.Broken
The radiobuttons are in a radiobuttongroup. they do insert these values in the db but on calldata button click the apropriate radiobutton doesnt get checked.
I use a cursor and getString for the values, my code works for the edittexts and textviews but not the radiobuttons, can you guys please help me as to why it doesnt work?
My code below:
public void getAssetInfo(){
btnCheckAssetData.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
Cursor res = myDb.getAllData(BarcodeTextData.getText().toString());
if (res.getCount() == 0) {
//Show message
showMessage("Error", "No Data");
return;
}
//StringBuffer buffer = new StringBuffer();
while (res.moveToNext()) {
//txtAssetCatData.setText(res.getString(0));
scan_contentData.setText(res.getString(1));
BarcodeTextData.setText(res.getString(2));
AssetDesTxtBoxData.setText(res.getString(3));
//Radio buttons get checked from db value
if(res.getString(4) == "New"){
radBtnNewData.setChecked(true);
}
else if (res.getString(4) == "Good"){
radBtnGoodData.setChecked(true); ;
}
else if (res.getString(4) == "Fair"){
radBtnFairData.setChecked(true);
}
else if (res.getString(4) == "Poor"){
radBtnPoorData.setChecked(true);
}
else if (res.getString(4) == "Broken"){
radBtnBrokenData.setChecked(true);
}
txtAssetCatData.setText(res.getString(5));
}
//Show all data
//showMessage("Data", buffer.toString());
}
}
);
}
And in my dbhelper class:
public Cursor getAllData(String text)
{
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from AssetDetails where Asset_Barcode_Number ='" + text + "'", null);
return res;
}
Aucun commentaire:
Enregistrer un commentaire