Hello, I created a custom listview in the fragment, in which there is some textual information and an image to delete the record from the database.
In activity I spend reading the base.
cursor = mSqLiteDatabase.rawQuery("SELECT liked_id as _id, liked_presentation_id FROM liked", null); LikedListCursorAdapter likedListCursorAdapter = new LikedListCursorAdapter(getActivity(), cursor); lvItems.setAdapter(likedListCursorAdapter); // in the CursorAdapter class, I create a click event for the imageView to delete the row from the database.
public void bindView(View view, final Context context, final Cursor cursor) { idSpeaker = cursor.getInt(cursor.getColumnIndex("_id")); imageViewStatus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.w("id",String.valueOf(idSpeaker)); mDatabaseHelper = new DatabaseHelper(context); mSqLiteDatabase = mDatabaseHelper.getWritableDatabase(); mSqLiteDatabase.delete(mDatabaseHelper.TABLE_LIKED, "liked_id = ?", new String[] {String.valueOf(idSpeaker)}); cursor.requery(); notifyDataSetChanged(); } }); The problem is that when you click on an image, the last element in the listview is always deleted. How to make the cursor position equal to the position of the selected image in the listview?
getItemId()ID usinggetItemId()method - pavlofff