开发者

Push SQLite3 data to an ArrayList()

I have a table of data with two cols "id" and "name". I'm trying to get all the names into an ArrayList from the database. What is the best way to 开发者_JAVA技巧make this call and create the array?


That will be something like this:

ArrayList myResults = new ArrayList(); 
Cursor c = db.query(...your Query Parameters here...);
c.moveToFirst();
while(!c.isAfterLast())
{
    myResults.add(c.getString(1));
    c.moveToNext();
}

Assuming that you select in your query the id and the name column in that order. Than the columnindex of name will be 1.

Hope that helps.


Use the while loop to go through the cursor contains and add each values to ArrayList.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜