android - Database id and listview items id get discrete -


    getting stuck issue      getting messages database , shows in list, list having check boxes when pressed delete checked check box deleted database.         , when again click see message position of message's changed in database id remain same , further delete message message database not deleted because position id , database message id become different.      please give me suggestion solve issue thank in advance... 
  • this code clicking position , send position database database id different next time of deletion.

        onclicklistener listenerdel = new onclicklistener() {             @override             public void onclick(view v) {                 /** getting checked items listview */                 sparsebooleanarray checkeditempositions = getlistview().getcheckeditempositions();                 int itemcount = getlistview().getcount();                  for(int i=itemcount-1; >= 0; i--){                     if(checkeditempositions.get(i)){                         log.e("position",""+(i+1));                           adapter.remove(list.get(i));                         db.deletemessage(i);                     }                 }    //              checkeditempositions.clear();                 adapter.notifydatasetchanged();                }         };             

when have large list , not consistent id's there can problems when deleting iterator. try write function in database adapter takes item not iterator of loop, that:

public void deleteitem(item item){     sqlitedatabase db = this.getwritabledatabase();     db.delete(table_items, key_id + " = ?",             new string[]{string.valueof(item.getid())});     db.close(); } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -