在列表视图中选择多行,并从列表视图和数据库中删除所选记录

时间:2018-02-22 02:29:02

标签: android listview

在我的应用程序中,我正在显示数据库中的自定义列表。选择几行列表后,我想从Listview和数据库中删除这些行。怎么办?

2 个答案:

答案 0 :(得分:0)

如果您的ListView数据保存在List中,请在List中的项目模型中添加一个变量,以标记所选项目。单击删除按钮后,循环浏览List并从List中删除所选项目,并将其从DB中删除。循环后调用Adapter.notifyDatasetChange()

答案 1 :(得分:0)

所以你应该像下面那样包装你的项目:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dashboard-info list-requests request-negotiating" >
<div class="enquiry request-item request-negotiating-item" >1</div>
<div class="enquiry request-item request-negotiating-item" >2</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">3</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">4</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">5</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">6</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">7</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">8</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">9</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">10</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">11</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">12</div>
</div>
<div class="dashboard-title list-request-negotiating-loadmore loadmore" style="">load more</div>

然后你可以使用position来获取Item并将public class Item { private HashMap<String, String> content; private boolean isSelected; public HashMap<String, String> getContent() { return content; } public void setContent(HashMap<String, String> content) { this.content = content; } public boolean isSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } 设置为true或false。并将isSelected更改为List<HashMap<String, String>>