0

I just tried to implement SQLite database thing in my Android App. Maybe I am not getting everything perfectly at Android developer Guide, So, I just found a nice tutorial on web, from this website.

Moreover, I just understood everything I need and implementing well until the DELETION operation.

From that above mentioned website code, I have this code to delete single user:

// Deleting single contact
public static void deleteUserData(UserData data) {
    final SQLiteDatabase db = open();
    db.delete(USER_TABLE, KEY_ID + " = ?",
            new String[] { String.valueOf(data.getID()) });
    db.close();
}

In my Application i am getting text from Edittext and retrieving it and showing it on the ListView. Also implemented "listItem.onItemLongClickListener()" to delete an item from the ListView, as shown below:

    @Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
        long arg3) {
    //UserData dataView = new UserData();
    //DBAdapter.deleteUserData(dataView);   

    allData.remove(position);
    adapter.notifyDataSetChanged();

    return false;
}

I am not able to understand how to pass the correct argument to the deleteUserData(UserData data) method.

My problem here is How to delete single item and set the autoincremented primary key value accordingly.

P.S : Please refer to the above link for complete code reference in that site.

Thanks.

2
  • You want to reduce the autoincrement of primary to get reduced when you delete a data? Commented Feb 4, 2014 at 9:21
  • Excactly, But I also need to know how to delete the DATA(Single row in the above case); Commented Feb 4, 2014 at 9:25

1 Answer 1

2

you can get the index from position variable of click method, then get the userdata by using position like Userdata dt = userlist[position]; from the list that you bind with listview then you can call your delete method like deleteData(dt.getID())

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.