块引用
您好我在我的应用程序中使用了基本适配器但是当我点击删除按钮时删除了时间项但列表视图不刷新。我也使用了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
由于
答案 0 :(得分:2)
您应该从集合中删除该项目:GetAllitemDetails
,然后调用theAdapter.notifyDatasetChanged()
以刷新ListView。
答案 1 :(得分:0)
在删除按钮功能
中尝试此操作 list.remove(position);
notifyDataSetChanged();