0

For below tables:

create table professor {id varchar(255), first_name varchar(255), last_name varchar(255) };
create table student {id varchar(255), first_name varchar(255), last_name varchar(255) };

Suppose you have below query:

select professor.first_name, professor.last_name from professor
union
select student.first_name, student.last_name from student;

and suppose you need to use the resulting cursor in a ListView that uses a CursorAdapter. It is stated in the documentation that:

The Cursor must include a column named "_id" or this class will not work. Additionally, using MergeCursor with this class will not work if the merged Cursors have overlapping values in their "_id" columns.

How would you generate a unique _id column value of type long for each of the rows in the resulting cursor?

atakan
  • 133
  • 1
  • 1
  • 8
  • You could extend `BaseAdapter` instead and implement your adapter similarly to `CursorAdapter`, minus the parts that require an `_id`column – Karakuri May 24 '16 at 00:32
  • I did a little reading so I understand your question now, however, is there a reason they need to be of type `long`? – Daniel May 24 '16 at 19:00
  • Also, Is it possible for you to rename the `id` to `_id`? If not SQLite creates a hidden `rowid` column you could alias it _id. Check [this](http://stackoverflow.com/questions/3359414/android-column-id-does-not-exist) out. Look at Tim Wu's answer. – Daniel May 24 '16 at 19:08

0 Answers0