块引用
嗨,我在我的应用程序中使用了基本适配器,但是当我单击删除按钮时,时间项被删除但列表视图没有刷新。我也使用了 adapter.notifydatasetchanged()。但是没有用。请给我解决方案?
下面我提到了代码:
enter code here
class listViewEventsAdapterdatabase extends BaseAdapter {
LayoutInflater mInflater;
OnItemValueChange listener;
public listViewEventsAdapterdatabase(Context context) {
mInflater = LayoutInflater.from(context);
}
public void setOnItemChange(OnItemValueChange onlistener) {
this.listener = onlistener;
}
public int getCount() {
if (GetAllitemDetails != null) {
return GetAllitemDetails.size();
}
return 0;
}
public Object getItem(int arg0) {
return arg0;
}
public long getItemId(int arg0) {
return arg0;
}
@Override
public void notifyDataSetChanged(){
super.notifyDataSetChanged();
}
public View getView(final int position, View convertView,
ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.databaselistviewitem, parent,false);
holder = new ViewHolder();
holder.txtrestaurant_name = (TextView) convertView
.findViewById(R.id.databaseproductname);
holder.btn_delete = (Button) convertView
.findViewById(R.id.buttondelete);
holder.edt_quantity = (EditText) convertView
.findViewById(R.id.quantity);
holder.btn_update = (Button) convertView
.findViewById(R.id.bttonupdate);
holder.txt_amount = (TextView) convertView
.findViewById(R.id.amount);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtrestaurant_name.setText(GetAllitemDetails.get(position)
.get("product"));
holder.edt_quantity.setText(GetAllitemDetails.get(position).get(
"quantity"));
holder.txt_amount.setText(getDoublePrecision(GetAllitemDetails.get(position).get(
"price")));
holder.btn_delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
db = DatabaseHelper.delete_byID(GetAllitemDetails.get(position).get("id"));
Toast.makeText(getApplicationContext(), "Delete succesfully", 3000).show();
if (listener != null) {
Log.e("Callback", (Str_subtotal));
listener.totalAmount((Str_subtotal));
listener.delivarychargeAmount(String.valueOf(delivarycharge));
listener.totalamt(String.valueOf(total));
lv_data.invalidateViews();
adapter_list.notifyDataSetChanged();
}
}
});
holder.btn_update.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("**************Quantitysdfknsldf:"
+ holder.edt_quantity.getText().toString().trim());
db.updateData(GetAllitemDetails.get(position).get("id"),
DatabaseHelper.TABLErestaurant, holder.edt_quantity
.getText().toString());
Toast.makeText(getApplicationContext(), "Update succesfully", 3000).show();
if (listener != null) {
Log.e("Callback", (Str_subtotal));
listener.totalAmount((Str_subtotal));
listener.delivarychargeAmount(String.valueOf(delivarycharge));
listener.totalamt(String.valueOf(total));
}
}
});
return convertView;
}
}
enter code here
谢谢