2013-08-12 2 views
1

이 나는 ​​사용자 지정 목록보기 내 데이터베이스에 저장된 다음 3 개 항목을 표시 다음 버튼이있는 코드를 작성했습니다. 자동 증가 열인 id라는 열을 만들었습니다. 하지만 내 로그 고양이의 ID 열 값을 인쇄하려고 할 때 단지 0이 표시됩니다. 무엇이 잘못 되었나요?SQLite는 자동 증가 coulmn 문제

public class youtube_db extends SQLiteOpenHelper { 


    public static final String dataBase_NAME="YOUTUBE_database"; 
    private static final int dataBase_VERSION=1; 
    public static final String dataBase_TABLE="youtube_VIDEOS"; 
    public static final String[] COLS_List={"video_Name","video_Descrption","video_Img","video_Url","video_CountView","video_LIKES","video_CommentCount","id" }; 

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    //end of declaring attributes and tables conents 
    public youtube_db(Context context) { 
     super(context,dataBase_NAME, null, dataBase_VERSION); 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public void onCreate(SQLiteDatabase db) { 
     // TODO Auto-generated method stub 
     db.execSQL(
      " create table " + dataBase_TABLE + "(" + COLS_List[0] +" text not null , "+ COLS_List[1] 
       +" text not null , "+ COLS_List[2]+" text not null , "+COLS_List[3]+" text not null , "+COLS_List[4]+" integer , "+COLS_List[5] 
       +" integer , "+COLS_List[6]+" integer ,"+COLS_List[7]+" integer primary key autoincrement) ");     


    } 

여기에 내가 id 값 인쇄하는 것을 시도했다 :

public ArrayList<videos> getAllData(){ 
     ArrayList<videos> videoArray=new ArrayList<videos>(); 

     Cursor cursor= SQL_db.query(my_Database.dataBase_TABLE, my_Database.COLS_List, null, null, null, null, null); 

     for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){ 

      videos videoObject=new videos(); 
      videoObject.setVideoname(cursor.getString(0)); 
      videoObject.setDecscrption(cursor.getString(1)); 
      videoObject.setImageurl(cursor.getString(2)); 
      videoObject.setVediourl(cursor.getString(3)); 


      videoArray.add(videoObject); 

      Log.d("getAlLvideos", "ok.... "); 



     } 
     cursor.close(); 
     Log.d("after close cursor", "ok.... "); 

     return videoArray; 

    }//end of function get all data 

답변

2
: 모든 데이터를 얻을 수

ArrayList<videos> getAllvideosList=new ArrayList<videos>(); 
          getAllvideosList=connection.getAllData(); 
          connection.close(); 

          for(int i=0;i<getAllvideosList.size();i++){ 

            videos videoObject=new videos(); 

           videoObject.setVideoname(getAllvideosList.get(i).getVideoname()); 
           videoObject.setDecscrption(getAllvideosList.get(i).getDecscrption()); 
           videoObject.setImageurl(getAllvideosList.get(i).getImageurl()); 
           videoObject.setVediourl(getAllvideosList.get(i).getVediourl()); 

           Log.d("try to print id ", String.valueOf(getAllvideosList.get(i).getId())); 


           vlist.add(videoObject); 
           lview.setAdapter(new custome(MainActivity.this,vlist)); 
           ad.notifyDataSetChanged(); 

을 여기에 내 기능 여기

내 데이터베이스입니다

문제는 당신이 당신의 비즈니스 객체에 대한 setId 전화 해달라고입니다 : videoObject.

 videoObject.setId(cursor.getInteger(7)); 
+0

확인, 감사 어리석은 실수 ^^ :

는 당신을위한 루프에서이 줄을 추가! – Tolen

+0

나는 돕는다. :) –