2013-10-27 125 views
0

相反的retriving它在每個列表返回包名的數據我沒有找到我的mistake.Plz幫助我。這是一個擴展SQLiteOpenHelper從SQLite數據庫檢索數據到ListView中

public List<DICTIONARY> getAllcontacts() { 
      List<DICTIONARY> meaningList = new ArrayList<DICTIONARY>(); 

      String selectQuery = "SELECT * FROM " + Table_Name; 

      SQLiteDatabase db = this.getWritableDatabase(); 
      Cursor cursor = db.rawQuery(selectQuery, null); 


      if (cursor.moveToFirst()) { 
       do { 
        DICTIONARY dictionary = new DICTIONARY(); 
        dictionary.setId(Integer.parseInt(cursor.getString(0))); 
        dictionary.setWord(cursor.getString(1)); 
        dictionary.setMeaning(cursor.getString(2)); 
        // Adding contact to list 
        meaningList.add(dictionary); 
       } while (cursor.moveToNext()); 
      } 

      // return meaning list 
      return meaningList; 
     } 

這是我DbHelper類是我的MainActivity類別

DbHelper db = new DbHelper(MainActivity.this); 
    List<DICTIONARY> dictionary = db.getAllContacts(); 
     ArrayAdapter<DICTIONARY> arrayAdapter = new ArrayAdapter<DICTIONARY>(MainActivity.this,android.R.layout.simple_list_item_1, dictionary); 
     lv.setAdapter(arrayAdapter); 
     } 

回答

0

更改它

// Adding contact to list 
       contactList.add(dictionary); 

   meaningList.add(dictionary); 

應該是這樣

if (cursor.moveToFirst()) { 
       do { 
        DICTIONARY dictionary = new DICTIONARY(); 
        dictionary.setId(Integer.parseInt(cursor.getString(0))); 
        dictionary.setWord(cursor.getString(1)); 
        dictionary.setMeaning(cursor.getString(2)); 
        // Adding contact to Meaning List 
        meaningList.add(dictionary);//Changed Here 
       } while (cursor.moveToNext()); 
      } 
+0

我已經改變了我的代碼,但它也沒有工作 – Illusionist

+0

現在它的工作我發現我的錯誤感謝阿米特·古普塔幫助 – Illusionist

+0

如何顯示這在列表視圖 – Illusionist