0

I am trying to delete a row from my db. I'm using this method:

public void deletePlayerbyID(int id){mDb.delete(SQLITE_TABLE, KEY_ROWID +"="+id, null); }

called in activity :

listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
      @Override
      public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
              return onLongListItemClick(v,pos,id);
      }
      protected boolean onLongListItemClick(View v, final int pos, long id) {

              AlertDialog.Builder builder = new  AlertDialog.Builder(AndroidListViewCursorAdaptorActivity.this);
                  builder.setMessage("Are you sure to delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int id) {bdHelper.open();
                                 dbHelper.deletePlayerbyID(pos);
                                 Log.i("ListView", "onLongListItemClick id=" + pos);
                                 displayListView();
                             }
                         })

Why I cannot delete the selected row from listView ? I have a method that delete all db and it work.

4

3 回答 3

1

尝试以下语句,您将能够解决问题

db.delete("Table","TITLE=?",new String[]{title});

在那之后

adapter = new EntryAdapter(this, items);
         listview.setAdapter(adapter);
         adapter.notifyDataSetChanged();
于 2013-05-02T13:28:19.643 回答
0

listView从适配器正在使用的数据源中删除元素后,调用adapter.notifyDataSetChanged()并且视图将刷新以反映删除。

于 2013-05-02T13:27:33.157 回答
0

删除后使用 notifyDataSetChanged()

protected boolean onLongListItemClick(View v, final int pos, long id) {

              AlertDialog.Builder builder = new  AlertDialog.Builder(AndroidListViewCursorAdaptorActivity.this);
                  builder.setMessage("Are you sure to delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int id) {bdHelper.open();
                                 dbHelper.deletePlayerbyID(pos);
                                 Log.i("ListView", "onLongListItemClick id=" + pos);
  notifyDataSetChanged();
                                 displayListView();
                             }
                         })
于 2013-05-02T13:29:38.740 回答