我一直在尝试在sqlite android中更新我的数据,但它不起作用。此外,logcat中也没有显示错误消息。
以下是我的代码:
Dbadapter.java:
public boolean updateEntry(SalesItemInformationLV testing)
{
ContentValues values = new ContentValues();
try {
values.put(ENTRY_NAME, testing.getItemname());
values.put(ENTRY_TEL, testing.getCostprice());
values.put(ENTRY_SELLINGPRICE, testing.getSellingprice());
values.put(ENTRY_QTYSOLD, testing.getItemquantity());
values.put(ENTRY_DATESOLD, testing.getDatesold());
values.put(ENTRY_STAFFDISCOUNT, testing.getStaffdiscount());
}
catch (SQLiteException e)
{
Log.w(MYDBADAPTER_LOG_CAT, "Update failed!" + e.toString());
}
// updating row
int returnvalue = _db.update(DATABASE_TABLE, values, KEY_ID + " = ?", new String[] { String.valueOf(testing.getId()) });
return returnvalue==1 ? true : false;
}
MyItems.java:
public boolean updateDatabase(SalesItemInformationLV testing2, Context c)
{
MyDbAdapter db = new MyDbAdapter(c);
db.open();
boolean rowIDofUpdatedEntry = db.updateEntry(testing2);
db.close();
return rowIDofUpdatedEntry;
}
ListView.java,它将saleitem2对象意图传递给Edit.java:
MyItems mi2;
private ArrayList<SalesItemInformationLV> displayiteminfo2;
mi2 = MyItems.getInstance();
displayiteminfo2 = mi2.retrieveAllForlist2(getApplicationContext());
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SalesItemInformationLV saleitem2 = displayiteminfo2.get(position);
String namevalue = saleitem2.getItemname();
Intent myintent = new Intent(ListSaleItemActivity.this, EditSaleActivity.class);
myintent.putExtra("array", saleitem2);
startActivity(myintent);
Edit.java将使用Items.java中的update方法:
Bundle extras = this.getIntent().getExtras();
final SalesItemInformationLV sale1 = (SalesItemInformationLV)extras.getSerializable("array");
final int id1 = extras.getInt("itemID");
btnSaveChanges.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mc.updateDatabase(sale1, getApplicationContext());
}}
我一直想弄清楚,我认为我的Dbadapter.java可能有问题,但我不确定。请告诉我如何解决这个问题!