0

请帮助我,我有一个包含字符串的数据库(例如 fotonames )。我想将整个 fotonames 列读入一个数组列表。我怎样才能做到这一点?

4

2 回答 2

2
public Cursor getfotoname() throws SQLException
{
 String getRT = "SELECT fotonames from "+ TABLE_NAME+";";
 Cursor mCur = sqldb.rawQuery(getRT, null);
 return mCur;
}

现在当你打电话

Cursor mCursor=null;

mCursor= DatabaseObject.getfotoname();

ArrayList<WhateverTypeYouWant> mArrayList = new ArrayList<WhateverTypeYouWant>();
for(mCursor.moveToFirst(); mCursor.moveToNext(); mCursor.isAfterLast()) {
// The Cursor is now set to the right position
mArrayList.add(mCursor.getWhateverTypeYouWant(WHATEVER_COLUMN_INDEX_YOU_WANT));
}
于 2012-04-05T08:57:22.243 回答
1

看看这个教程会帮助你 http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/

在这里您可以了解如何从一列中获取所有值 http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/3/#getrowasarray

或者其他方式是

像这样触发查询

 public Cursor columnValues() throws SQLException{
            // TODO Auto-generated method stub


            Cursor mCursor = db.query(Course_Info_Table,
                              new String[] {Column1 , column2 },
                                            null,null, null, null, null);




                    //Cursor mCursor = mDb.rawQuery("Select",null);
                    if (mCursor != null)
                    {
                    mCursor.moveToFirst();
                    }

                    return mCursor;



        }

并像接收它一样接收它

    ArrayList<String> list1  = new ArrayList<String>();

    ArrayList<String> list12 = new ArrayList<String>();

cursor = dbm.columnValueofCourse();
        cursor.moveToFirst();
        startManagingCursor(cursor);

        for (int i = 0; i < cursor.getCount(); i++) {

        String  reciv = cursor.getString(cursor
                    .getColumnIndex("column1"));

String      reciv3 = cursor.getString(cursor
                    .getColumnIndex("column2"));



            list1.add(reciv);
            list2.add(reciv3);
            cursor.moveToNext();
        }
于 2012-04-05T08:51:30.733 回答