0

我没有发现我的错误,而不是检索它在每个列表中返回包名称的数据。请帮助我。这是我的扩展 SQLiteOpenHelper 的 DbHelper 类

 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;
        }

这是我的 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);
        }
4

1 回答 1

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());
            }
于 2013-10-27T19:58:39.197 回答