Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safe number range for my own IDs in dynamic layout?

I am developing an Activity with a fixed and a dynamic layout part. The dynamic part (and thus the number and type of created widgets) is based on database values this way: For every database row, I will have a group of widgets. And the components of each group depend on the object type (determined from one of the columns) of that database row.

For saving / restoring instance state, all widgets need to have IDs. I would like to ensure that my own IDs will never conflict with IDs that from the generated R class.

For better handling within the app (finding which widget maps to which field in which data object), a numbering scheme like ID = row * 100 + fieldindex would be helpful. Fieldindex is not exactly a colum number. Every object type should have its own fieldindices.

As the ID values in generated R seem not to have consecutive numbers, I can not just predefine a pool of IDs in R and used these without the need of an additional mapping. Second reason against a predefined pool: The big number of fieldindices would result in a large ID pool. Third, the size of the ID pool would limit the row count that can be displayed.

Is there a safe number range I can use for my own layout component's IDs ? Looking at R.java in the gen/ folder, I have the impression that generated IDs are all greater than 0x7f000000. Is that guaranteed ? And if yes, is the range from 0x00000000 up to 0x7f000000 free to use or is it reserved for android's internal purposes ?

like image 300
Genius Androidus Avatar asked Jan 23 '12 23:01

Genius Androidus


1 Answers

Why do you want to avoid the same id? Only thing that necessary is: An ID need not be unique throughout the entire tree, but it should be unique within the part of the tree you are searching. So, you can use your formula

ID = row * 100 + fieldindex

I will work fine, even if it is not unique in project.

like image 184
Jin35 Avatar answered Nov 07 '22 14:11

Jin35