无法从Android

时间:2017-03-19 19:12:58

标签: android

我想从sqlite数据库中检索数据并希望在android中创建数组,但它只给了我9个元素,还有很多其他元素,但是它没有显示。我能做什么?提出一些建议............

我已经尝试过了:

String selectQuery1 = "SELECT * FROM rcategories";
Cursor c = db.sqliteDataBase.rawQuery(selectQuery1, null);

if(c.getCount()>=1){
    recipeNamearray = new String[c.getCount()];

    int i=0;

    while(c.moveToNext()) {
        recipeNamearray[i]=c.getString(c.getColumnIndex("rcategary"));
        i++;
    }

1 个答案:

答案 0 :(得分:0)

这里是你的getdata的编辑代码:

    String selectQuery1 = "SELECT * FROM rcategories";
    Cursor c = db.sqliteDataBase.rawQuery(selectQuery1, null);

     if(c.getCount()>=1){
         recipeNamearray = new String[c.getCount()];
         int i=0;
         // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                recipeNamearray[i]=c.getString(c.getColumnIndex("rcategary"));        
                i++;
             } while (cursor.moveToNext());
        }
    }

参考来自:http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/