Charles Lynch
Charles Lynch

Reputation: 221

One Column to Array SQLite

can someone tell me how to change a column to an array ???

Im Making a Database and want view one of my column in android.

I have 6 column, but i just want one column from them to be an array for my listview.

Here is my table :

static final String KEY_ROWID = "_id";
static final String KEY_A = "a";
static final String KEY_B = "b";
static final String KEY_C = "c";
static final String KEY_D = "d";
static final String KEY_E = "e";

My goal is to make the "a" column to an array like this :

String arraylist[] = { "a" column data };

how can i get that ????

Upvotes: 0

Views: 616

Answers (1)

Peter Birdsall
Peter Birdsall

Reputation: 3425

It sounds like you should be using the cursor adapter, but if you have a good reason to use the array here's the gist of how I'd do it.

String arraylistA[];
...
yourCursor.moveToNext();
i = 0;

...
arraylistA[i] = { (yourCursor.getString(yourCursor.getColumnIndex(YourDBHelper.yourcolumnnameA))};
i + 1;
                                            or
arraylistA[i] = { (yourCursor.getString(yourCursor.getColumnIndex("yourcolumnnameA"))};
i + 1;

And then you loop thru the moveToNext and the valuation of the arraylistA. You will obviously have to define your other lists and a better loop.

Upvotes: 1

Related Questions