gpt4 book ai didi

java - 使用 SQLite 从 ListView 中删除项目

转载 作者:行者123 更新时间:2023-12-02 01:58:01 25 4
gpt4 key购买 nike

我的 ListView 中有一个奇怪的问题,我不明白为什么会发生这种情况。

在我的 list 中,当我选择3个或更多项目时,仅最后一个和第一个项目被删除,第二个项目不会被删除。它只是保持选中状态,我需要再次单击此帖子按钮。

SendDataFragment Activity

   btn_DataSend=(Button) getActivity().findViewById(R.id.trn_post_btn);
btn_DataSend.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
StringBuffer responseText = new StringBuffer();
responseText.append("The following were selected...\n");

//get All info like custID, mStatus mTrnNo mCustID mCustName
List<customerInfo> stateList = adapter.mCategories;

for(int i=0;i<stateList.size();i++)
{
customerInfo state = stateList.get(i);
if(state.ismStatus())
{
//postData(state.getmTrnNo());
int c = i;
dbManager.delete_ShipmentDetails(state.getmCustID());
stateList.remove(i);
}
}
adapter.notifyDataSetChanged();
Toast.makeText(getActivity(), responseText, Toast.LENGTH_LONG).sho();
}
});

DBManager

 public void delete_ShipmentDetails(String id){
SQLiteDatabase db = dbHelper.getReadableDatabase();
db.execSQL("delete from "+ DatabaseHelper.TBL_OE_SHIPMENT_H +" WHERE " +DatabaseHelper.OE_SHIPMENT_H_CUSTID+"="+id);
}

My App screen-shots are:

Before Remove Item After Remove Item

最佳答案

以相反的顺序使用循环

 for(int i = stateList.size()-1; i >= 0; i--){
customerInfo state = stateList.get(i);
if(state.ismStatus())
{
//postData(state.getmTrnNo());
int c = i;
dbManager.delete_ShipmentDetails(state.getmCustID());
stateList.remove(i);
notifyItemRemoved(i);
}
}

adapter.notifyDataSetChanged();

关于java - 使用 SQLite 从 ListView 中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52054891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com