我已经尝试了所有的东西,但我无法得到正确的结果,我也尝试
adapter.clearAll()
adapter.notifyDataSetChanged()
但是当我从列表视图中删除它从其位置删除的行但是当我更改另一行的值而不是删除过程完美地工作但是更改了值而没有从数据库完全设置值时,我无法得到结果。
这是我的代码,请帮助我,告诉我哪里做错了。
提前谢谢
Delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Identifier_fev = null;
String Default_Option = null;
String Quantity1 = null;
jffDatabase.open();
Cursor identifie = jffDatabase.getALL();
if (identifie.moveToPosition(position)) {
Identifier_fev = identifie.getString(identifie.getColumnIndexOrThrow("identifier"));
Default_Option = identifie.getString(identifie.getColumnIndexOrThrow("default_option"));
}
jffDatabase.delete(Identifier_fev, Default_Option);
identifier.remove(position);
title.remove(position);
defaultPrice.remove(position);
default_option.remove(position);
price.remove(position);
quantity.remove(position);
Cursor c1 = jffDatabase.getALL();
if (c1.moveToFirst()) {
do {
Quantity1 = c1.getString(c1.getColumnIndexOrThrow("quantity"));
update_quantity.add(Quantity1);
} while (c1.moveToNext());
}
for (int i = 0; i < update_quantity.size(); i++) {
Toast.makeText(ctx, "" + update_quantity, Toast.LENGTH_LONG).show();
Quantitylbl.setText(update_quantity.get(i).toString());
Toast.makeText(ctx, "set " + Quantitylbl.getText().toString(), Toast.LENGTH_LONG).show();
}
Quantity();
notifyDataSetChanged()
AddtoCartActivity.Cartcount.setText(String.valueOf(sum));
}
});
答案 0 :(得分:2)
好的做法是使用界面
创建新界面
INotifyPropertyChanged
然后通过此接口实现Activity
public interface MyCustomObjectListener {
public void RefreshList();
//add parameter for delete if required ex-
//public void RefreshList(String Item_id);
}
实施方法
YourActivityName extends Activity implements MyCustomObjectListener
从Base适配器onClick可以像这样调用方法RefreshList
@Override
public void RefreshList() {
// Do your delete task and clear current List and get updated list task here
}
您可以从((YourActivityName)mContext).RefreshList();
@Override