I have an app that creates controls programmatically according to information coming from a database.
In the application I need to reference a dynamically created Layout, so that I need to assign it an ID.
Currently, I have:
final Random random = new Random();
for (int i = 0; i < count; i++) {
TdcItem item = items[i];
int id = item.getID();
final int layoutId = random.nextInt(id * (id + 1));
....
}
Where id variable is an ID coming from the database, which of course is unique in database table.
The problem is that I am also creating buttons coming from another table, so, the ID's are unique from that table point of view, however, some of them are not unique in activity context.
That cause that when I use findViewById trying to find a layout, a button is found instead, throwing an invalid cast exception.
Is there a way to create unique ID's for the layouts?
Thanks Jaime