마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

아무 에러도 뜨지 않는데 원하는 대로 삭제가 안돼요 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ

0 추천
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
   public boolean onItemLongClick(AdapterView<?> parent, View view,
     final int position, long id) {

    AlertDialog diaBox = new AlertDialog.Builder(
      ListViewTestActivity.this)
      .setTitle("Delete")
      .setMessage("Really Delete?")
      .setIcon(R.drawable.ic_launcher)
      .setPositiveButton("YES",
        new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog,
           int whichButton) {
             SQLiteDatabase db=null;
           if(db==null){
            db=openOrCreateDatabase("test.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
           }











~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private static final String Q_CREATE_TABLE= "CREATE TABLE IF NOT EXISTS "&nbsp; +&nbsp; TB_NAME+ " (_id INTEGER PRIMARY KEY AUTOINCREMENT "
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + "," + "title TEXT "
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + "," + "contents TEXT"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + ");";
&nbsp;
&nbsp;private final String Q_GET_LIST= "SELECT * FROM test" + " ORDER BY +_id DESC"; 

public class DBManager extends SQLiteOpenHelper {
 private final static String TB_NAME = "test";
 public static final String DB_NAME = "test.db";
 public static final int DB_VERSION = 1;
 public static final String KEY_ID = "_id";
 private int _id=0;
 public static final String TITLE = "title";
 public static final String CONTENTS = "contents";
 String quary ;
 private final String Q_GET_LIST= "SELECT * FROM test" + " ORDER BY +_id DESC"; 
 //constructor
 public DBManager(Context context) {
 super(context, DB_NAME, null,DB_VERSION);
 quary = "CREATE TABLE IF NOT EXISTS "+ TB_NAME&nbsp; +" (_id INTEGER PRIMARY KEY AUTOINCREMENT "
 + "," + " title TEXT "
 + "," + " contents TEXT "
 + ");";
 }

만든 db&테이블은 각각 이것인데 아무 에러도 안뜨고 삭제도 안돼요 ㅠㅠㅠㅠㅠㅠㅠㅠ
yes를 누르면 아무 반응도 일어나지 않습니당 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ

 

제발 도와주세요 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ table값이 제대로 선택이 안된건가요?? ㅠㅠㅠㅠㅠㅠㅠㅠㅠ

초보 안드롱 (480 포인트) 님이 2014년 5월 31일 질문
초보 안드롱님이 2014년 5월 31일 태그 변경

1개의 답변

+1 추천
 
채택된 답변
DELETE쿼리문은 어디있나요??
YeonMin (17,860 포인트) 님이 2014년 5월 31일 답변
초보 안드롱님이 2014년 6월 1일 채택됨
/* 리스트뷰 롱클릭시 삭제 다이얼로그 */
        listView.setOnItemLongClickListener(new OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> parent, View view,
                    final int position, long id) {
            //    String[] from = new String[] { BaseColumns._ID, COL1 };
            //    int[] to = new int[] { R.id.rec_id, R.id.rec_memo };
                switch(position){
                default:
                AlertDialog diaBox = new AlertDialog.Builder(
                        ListViewTestActivity.this)
                        .setTitle("Delete")
                        .setMessage("Really Delete?")
                        .setIcon(R.drawable.ic_launcher)
                        .setPositiveButton("YES",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int whichButton) {
                                           SQLiteDatabase db=null;
                                         if(db==null){
                                             db=openOrCreateDatabase("test.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
                                         }
                                        
                                    
                                        
                                         if(db != null){
                                             //db.close();
                                         }
                                     //    intent.putExtra("id", Long.toString(_id));
                                        
                                        
                                         //System.out.println("_id -> " + "_id");

                                          Cursor cursor = db.rawQuery("SELECT * FROM test", null);
                                     //    int id=0;
                                     //    id=Integer.parselnt("_id");
                                         cursor.moveToPosition(position);
                                         int i = cursor.getInt(cursor.getColumnIndex("_id"));
                                     db.execSQL("DELETE FROM test WHERE _id = "+i+" ");   
                                  //List 액티비티에서 넘긴 선택한 리스트뷰의 id 값
                                 //    String id=getIntent().getExtras().getString("id");
                                 //    _id=Integer.parseInt(id); // _id 값으로 질의를 하려면 정수형으로 형 변환해야 함
                                     Cursor c=db.rawQuery(Q_GET_LIST, null);
                                     listView=(ListView) findViewById(R.id.listView);
                                     adapter1=new SimpleCursorAdapter(
                                             getApplicationContext(),
                                             android.R.layout.simple_list_item_2,
                                             c,
                                             new String[] {"title", "contents"},
                                             new int[] {android.R.id.text1, android.R.id.text2}           
                                             );
                                     listView.setAdapter(adapter1);
                                         //String query="DELETE FROM test WHERE _id= " + _id;
                                         //db.execSQL(query);
                                         //finish(); //현재 액티비티 종료
                                        // Builder.show();
                                    }
                                     
                                }).setNegativeButton("NO", null).create();
                diaBox.show();
                break;
                }
                return false;
            }
           
           
               
           
       
           
            });
       

    }// 수정 한뒤

position 값을 받아왔는데 position이랑 id랑 따로 돌아가네용.. ㅜ 대칭적으로 지워져요..
아무튼 감사합니당 !!!!!!!!!!!!!!
일단 int형을 스트링으로 바꾸는건 Integer.toSting입니다~
부족한 답변이라 만족 못 시켜드린점 죄송합니다 ㅜ
아니에요 ㅎㅎ 감사합니다!! 진짜 ㅠㅠㅠ
...