我想使用我的 SQLHandler的这个删除功能:
public void removeProduct(int id) {
try {
String a;
a = Integer.toString(id);
getWritableDatabase().delete(TABLE_INCOME, KEY_ID + " = ?", new String[] { a });
} catch (Exception e) {
e.printStackTrace();
}
}
我在我的视图活动中这样使用它:
viewHolder.txt_price.setText( Long.toString(_incomelist.get(position).getPrice()).trim());
viewHolder.txt_type.setText(_incomelist.get(position).getType().trim());
viewHolder.txt_date.setText(_incomelist.get(position).getDate().trim());
viewHolder.txt_desc.setText(_incomelist.get(position).getDescription().trim());
viewHolder.txt_pmode.setText(_incomelist.get(position).getPaymode().trim());
final int temp = position;
(convertView.findViewById(R.id.imageButton2))
.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
AlertDialog.Builder alertbox = new AlertDialog.Builder(
ViewContact.this);
alertbox.setCancelable(true);
alertbox.setMessage("Are you sure you want to delete ?");
alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
try{
db.removeProduct(temp);
ViewContact.this.onResume();
Toast.makeText(getApplicationContext(),"Deleted..",Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
alertbox.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface arg0, int arg1) {
}
});
alertbox.show();
}
});
问题部分是它没有抛出任何类型的异常。请纠正我!或者请告诉我如何调用这个函数?