我有購物車頁面,但問題是,我不能從購物車刪除項目時,點擊刪除圖片,在我的數據庫中我有刪除方法,並ListView中我刪除即可圖像,給OnClickListener的適配器,請看看我的代碼,並建議我.. DataBasehelper1.java:刪除行的車時,點擊刪除列表中的ImageVIewof行項目
public int deleteContact(int id) {
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(CONTACTS_TABLE_NAME, CONTACTS_PRODUCT_ID + " = "+id, null);
}
ListViewAdapter.java:
public class ListViewAdapter extends BaseAdapter {
String productId = "0";
public View getView(final int position, View convertView, ViewGroup parent) {
holder.remove =(ImageView)convertView.findViewById(R.id.removeIV);
holder.remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
db.deleteContact(Integer.valueOf(productId));
//list.remove(getItem(position));
Toast.makeText(v.getContext(), "removed ",Toast.LENGTH_SHORT).show();
}
});
}
所以你我猜你已經調用了一個函數來刪除,但你沒有通過刪除視圖來更新UI – himanshu1496
你也刪除了一個productId,它的值爲零,所以總是刪除你的數據庫中的特定行 – himanshu1496