目前,我创建了一个包含列表视图的应用程序。我使用库“com.baoyz.swipemenulistview:library:1.3.0”来显示我的数据列表。在这个列表视图中,我添加了一个删除数据的函数。如果用户想从列表视图中删除一项,只需从右向左滑动,就会显示一个“删除”按钮。现在,我已经对按钮删除进行了编码,以便用户选择的项目将被删除。问题是用户单击删除按钮后,它会吐司“已删除项目”。但如果用户打开列表视图,它不会删除。我不知道为什么。下面是我的代码:JAVA listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(int position, SwipeMenu menu, int index) { switch (index) { case 0: String report_id = null; deleteTask(report_id); Toast.makeText(TaskList.this,"Item deleted",Toast.LENGTH_SHORT).show(); Intent intent = new Intent(TaskList.this, Home.class); startActivity(intent); break; } // false : close the menu; true : not close the menu return false; } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TaskClass taskClass = taskClassArrayList.get(position); Intent intent = new Intent(TaskList.this, TaskUpdateBefore.class); intent.putExtra("task", taskClass); startActivity(intent); } }); retrieveJSON();}private void deleteTask(final String report_id) { showSimpleProgressDialog(this, "Loading...","Please wait",true); StringRequest stringRequest=new StringRequest(Request.Method.POST, URLs.URL_DELETE_TASK, new Response.Listener<String>() { @Override public void onResponse(String response) { Toast.makeText(TaskList.this,response, Toast.LENGTH_LONG).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } })
1 回答
ITMISS
TA贡献1871条经验 获得超8个赞
忘记“FROM”关键字,这是 sql 查询删除的语法
DELETE FROM ot_report WHERE report_id = '$report_id';
安卓
TaskClass taskObject = (TaskClass) listView.getItemAtPosition(position);
reportId = taskObject.getId()//your field;
deleteTask(reportId);
- 1 回答
- 0 关注
- 150 浏览
添加回答
举报
0/150
提交
取消