jul
jul

Reputation: 37464

How to get only one column as the result of a query with ActiveAndroid?

How can I get an array with only the column "Name" of my Category model?

I can get all my categories using

List<Category> categoryList = new Select()
    .from(Category.class)
    .execute();

and then create another array with the name of the Category, but I guess there is a way to get it directly and I cannot find how.

Upvotes: 4

Views: 2792

Answers (1)

sjwoodr
sjwoodr

Reputation: 326

A little late in answering this, but the issue is because SQLiteUtils.rawQuery() makes the assumption that the Id column is always going to be in the cursor result. Set your columns String[] to {Id, your_column} and you'll be fine.

List<Category> categoryList = new Select(new String[]{"Id,your_column"}).from(Category.class).execute();

Upvotes: 12

Related Questions