2017-04-20 28 views
0

這是插入代碼SQLlite要求任何回報

   for(int i = 0 ;pseudo.size() <= i; i++){ 
       ContentValues values = new ContentValues(); 
       String contact = (String) pseudo.get(i); 
       values.put("pseudo", contact); 
       values.put("adresse", "test"); 
       values.put("image", "test"); 
       values.put("ID", "5"); 
       dbwrite.insert("Contact", null, values); 
      } 

,這是讀碼

String[] retour = { 
     "pseudo", 
     "xmppadresse", 
     "image", "ID" 
     }; 
    Cursor cursor = dbread.query("Contact", retour, null, null, null, null, "pseudo"); 
    Log.d("debug", "populateWithInitialContacts: "+cursor.getCount()); 
    while(cursor.moveToNext()) { 
     String pseudo = cursor.getString(cursor.getColumnIndexOrThrow("pseudo")); 
     Log.d("debug", "getcontact: "+pseudo); 
     listcontact.add(new Contact(pseudo)); 
    } 
    cursor.close(); 

我的要求任何回報(這是使用databasse SQLite的Android中我第一次)

+0

什麼'Log.d(「debug」,「populateWithInitialContacts:」+ cursor.getCount());'print out? – petey

+0

@petey這個日誌打印「populateWithInitialContacts:0」 – therapha361

回答

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

這不是你遍歷列表的方式。你可能想要類似

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

噢謝謝 我覺得我現在很累^^。 – therapha361