android - Listview 只有最后一个日期被删除
问题描述
以下代码包含用于显示来自 sqlite 的数据的 listview 函数。
问题是无论我选择了哪些数据,它只会删除最后一个数据,而不是正在选择的数据。我该如何解决这个问题?请帮忙。
谢谢你。
Arealist.java
public class Arealist extends AppCompatActivity {
public static ListView listView;
public static ArrayList<Area> list;
AreaListAdapter adapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
listView = (ListView) findViewById(R.id.listView);
list = new ArrayList<>();
adapter = new AreaListAdapter(this, R.layout.area_items, list);
listView.setAdapter(adapter);
//get all data
Cursor cursor = MainActivity.sqLiteHelper.getData("SELECT * FROM AREA");
list.clear();
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
double area = cursor.getDouble(1);
String date = cursor.getString(2);
list.add(new Area(id, area, date));
}
adapter.notifyDataSetChanged();
}
解决方案
看来您的问题出在这一行MainActivity.sqLiteHelper.deleteData(Area.getId());
试试这个
MainActivity.sqLiteHelper.deleteData(area.getId());
推荐阅读
- php - 在 php 中使用 strpos 查找对象中的特定单词
- javascript - 如何访问嵌套在 div 中的表单数据(TypeScript)
- python - Jupyter 小部件 clear_output() 不起作用
- javascript - Web Audio API:为什么只能启动一次源?
- python - Matplotlib:不可能同时关闭轴和设置 facecolor?
- blockchain - 基于区块链的系统如何保证区块的不变性?
- android - RecyclerView、Fragment、Android 中的 java.lang.ClassCastException
- python - 获取 QTreeWidgetItem 的最顶层项
- npm - 如何在 Sails.js 中使用 import Leaflet?
- python - Pyspark:如何读取带有时间戳的 csv 文件?