tags:

views:

2691

answers:

1

I get a String data from Cursor, but I don't know how to convert it to Array. How can I do that?

String[] mString;
for(cursor.moveToFirst(); cursor.moveToNext(); cursor.isAfterLast()) {
   mTitleRaw = cursor.getString(cursor.getColumnIndex(SBooksDbAdapter.KEY_TITLE_RAW));
}
mString = mTitleRaw ????
+2  A: 

You could just wrap mTitleRaw into a single element array like so:

mString = new String[] { mTitleRaw };

Update: What you probably want is to add all the rows to a single array, which you can do with an ArrayList, and mutate back to a String[] array like so:

ArrayList strings = new ArrayList();
for(cursor.moveToFirst(); cursor.moveToNext(); cursor.isAfterLast()) {
   String mTitleRaw = cursor.getString(cursor.getColumnIndex(SBooksDbAdapter.KEY_TITLE_RAW));
   strings.add(mTitleRaw);
}
Sting[] mString = (String[]) strings.toArray(new String[strings.size()]);
marshall_law
Thanks so much!
Dennie
Are you sure that for is good? Your first element is skipped, Shouldn't been: for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
Pentium10