mercredi 24 février 2016

cant delete the values from sqlite second time- android

the problem i am facing is when i added values after opening the app second time it add values in db but cant delete it from the db , i dont know where i am doing mistake , and thnks alot in advace here my db class method

     public boolean deletesinglerow(Integer rowid) {

    SQLiteDatabase obj = this.getWritableDatabase();
 //i added +1 here coz it without it deleted the previous id value
     rowid = rowid +1;
    obj.delete(TABLE_NAME, COL_1 + "=" + rowid, null);


    return  true;
}

and here is the method from which i am calling this metd

           listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long iddb) {

            Boolean deletedrows=myDB.deletesinglerow(Integer.valueOf((int) iddb));
            if(deletedrows==true){

                Toast.makeText(StarMessages.this,"Deleted",Toast.LENGTH_LONG).show();
                messageAdapter.remove(arrayList.get(position));
                listView.setAdapter(messageAdapter);
                messageAdapter.notifyDataSetChanged();
            }else {
                Toast.makeText(StarMessages.this,"cant delete",Toast.LENGTH_LONG).show();
            }

            return true;
        }
    });

Aucun commentaire:

Enregistrer un commentaire