안드로이드 개발 질문/답변
(글 수 45,052)
ListView av = getListView(); av.setAdapter(adapter); av.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick( AdapterView<?> parent, View view, int position, long id) { // Check for delete button final long deletePetId = id; // Use an Alert dialog to confirm delete operation new AlertDialog.Builder(List.this) .setTitle("DB자료 삭제") .setMessage("선택하신 자료를 삭제하시겠습니까?") .setPositiveButton("삭제", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mDbHelper.deleteRow(deletePetId); } }) .setNegativeButton("취소", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Refresh the data in our cursor and therefore our List } }) .show(); } });
위의 소스를 보면
리스트에 뿌려주는것은 제대로 나오는데, 그 리스트 항목을 클릭하면
다이얼로그를 보여주어, 삭제 및 취소 버튼을 클릭 시 각 해당 메소드를 실행하게 하고 싶습니다.
뭐가 잘못된것인지 삭제가 되지를 않고 오류메세지가 출력됩니다. ㅠㅠ
고수분들 조언좀 ㅠㅠ
그리고 position값을 id대신 집어 넣어보시는 게 어떨까요.
아 커서 순서대로 리스트에 안들어가 있으면 안되려나 .... 이상 허접한 답변 이었습니다.