ActiveAndroid如何从表中获取单个列项并将其存储在arraylist中

时间:2015-10-18 20:22:49

标签: android activeandroid

我是活跃的android的新手,我有一个名为MyTable的表,其中包含articleName,articleId和imageTicket列,我想将所有imageTicket列值存储在ArrayList中。任何人都可以帮我查询?

2 个答案:

答案 0 :(得分:4)

这是我从MyTable获取imageTicket列的代码

 private ArrayList<MyTable> myTableList = new ArrayList<MyTable>();
 // to get all table data
 myTableList =  new Select().from(MyTable.class).execute();

 for(int i = 0; i < myTableList.size(); i++){         
     String imageTicket = myTableList.get(i).getImageTicket();
     // do something with imageticket value
 }

答案 1 :(得分:1)

你可以使用这样的东西: SQLiteDatabase db = this.getReadableDatabase();

// 2. build query
Cursor cursor = 
        db.query(TABLE_NAME, // a. table
        COLUMNS, // b. column names
        " id = ?", // c. selections 
        new String[] { String.valueOf(id) }, // d. selections args
        null, // e. group by
        null, // f. having
        null, // g. order by
        null); // h. limit

了解更多信息:http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html