小编Jas*_*son的帖子

从android中的数据库读取到arraylist

我是Android开发的新手,无法弄清楚如何从我database/table的数据库读取.现在我有:

      Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);

       int Column1 = c.getColumnIndex("Field1");
       int Column2 = c.getColumnIndex("Field2");

       // Check if our result was valid.
       c.moveToFirst();
       if (c != null) {
        // Loop through all Results
        do {
         String Name = c.getString(Column1);
         int Age = c.getInt(Column2);
         Data =Data +Name+"/"+Age+"\n";
        }while(c.moveToNext());
       }
       TextView tv = new TextView(this);
       tv.setText(Data);
       setContentView(tv);
      }
      catch(Exception e) {
       Log.e("Error", "Error", e);
      } finally {
       if (myDB != null)
        myDB.close();
      }
Run Code Online (Sandbox Code Playgroud)

我怎么把它读成一个arraylist?

sqlite android arraylist

4
推荐指数
2
解决办法
8041
查看次数

标签 统计

android ×1

arraylist ×1

sqlite ×1