나는 텍스트 상자와 이미지가있는 사용자 지정 목록을 만들었습니다. 이미지는 데이터베이스 sqlite에서 행을 삭제해야합니다.cursoradapter의 ListView에서 항목 삭제
내 조각 활동에 sqlitedatabase 쿼리 메서드를 사용하고 있습니다.
cursor = mSqLiteDatabase.rawQuery("SELECT liked_id as _id, liked_presentation_id FROM liked", null);
LikedListCursorAdapter likedListCursorAdapter = new LikedListCursorAdapter(getActivity(), cursor);
lvItems.setAdapter(likedListCursorAdapter);
///////////// 내 cursoradapter
public class LikedListCursorAdapter extends CursorAdapter {
SQLiteDatabase mSqLiteDatabase;
int idSpeaker,idPresentation;
TextView textViewName, textViewCompany, textViewTitle, textViewDate, textViewAboutReport;
LinearLayout linearLayout;
public static ImageView imageViewStatus;
private DatabaseHelper mDatabaseHelper;
public LikedListCursorAdapter(Context context, Cursor cursor) {
super(context, cursor);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.liked_list, parent, false);
}
@Override
public void bindView(View view, final Context context, final Cursor cursor) {
imageViewStatus = (ImageView) view.findViewById(R.id.imageViewStatus);
textViewTitle = (TextView) view.findViewById(R.id.textViewTitle);
textViewDate = (TextView) view.findViewById(R.id.textViewTime);
idSpeaker = cursor.getInt(cursor.getColumnIndex("_id"));
///////////////delete item
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();
}
});
그러나, 항상 목록보기의 마지막 행을 제거합니다. (커서 위치가 마지막 임).
내가 클릭하면 listview에서 현재 위치를 얻는 방법을 모르겠습니다. 제발 도와주세요
작동하지 않습니다. cursorview.getposition() = listview의 마지막 인덱스 필자가 아는 한, listview에서 인덱스 행을 찾아 cursor.movetoposition (index)로 전송해야합니다. 다음 작동합니다 –
이 추가 cursor.moveToPosition (위치) 전에 idSpeaker –