Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

android - Sqlite how to get string items using cursor

public Cursor getImages(long rowId) throws SQLException
    {
        Cursor mCursor =
                db.rawQuery("select * from Pictures WHERE id=" + rowId + ";", null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;


    }

Table columns "id, pic, comment"

I want to take values of pic & comment to string array.

My code is:

int i=0;
        Cursor c1 = db.getImages(memberId);     
        c1.moveToFirst();
        while(c1.isLast()){
            pictures[i]=c1.getString(1);
            comments[i]=c1.getString(2);
            i++;
        }

this not working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should do it like this:

c1.getString(cursor.getColumnIndex("pic"));

and

c1.getString(cursor.getColumnIndex("comment"));


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...