目前,我創(chuàng)建了一個(gè)包含列表視圖的應(yīng)用程序。我使用庫“com.baoyz.swipemenulistview:library:1.3.0”來顯示我的數(shù)據(jù)列表。在這個(gè)列表視圖中,我添加了一個(gè)刪除數(shù)據(jù)的函數(shù)。如果用戶想從列表視圖中刪除一項(xiàng),只需從右向左滑動(dòng),就會(huì)顯示一個(gè)“刪除”按鈕?,F(xiàn)在,我已經(jīng)對(duì)按鈕刪除進(jìn)行了編碼,以便用戶選擇的項(xiàng)目將被刪除。問題是用戶單擊刪除按鈕后,它會(huì)吐司“已刪除項(xiàng)目”。但如果用戶打開列表視圖,它不會(huì)刪除。我不知道為什么。下面是我的代碼: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貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊
忘記“FROM”關(guān)鍵字,這是 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 關(guān)注
- 199 瀏覽
添加回答
舉報(bào)
0/150
提交
取消