Is it possible to get android to give me a custom id?
so for example if I already have defined in xml:
R.id.some_layout
R.drawable.some_drawable
is there any function like this
R.custom_id("a_custom_id")
so I could then access as
R.id.a_custom_id
You can not dynamically create new IDs. Even if
Rwas capable of doing so, you wouldn’t be able to access it usingR.id.a_custom_id. Java is not dynamic language, and cannot add fields at runtime.There is, however, compile-time solution. In your
res/values/ids.xmladd:And then you can reference
R.id.a_custom_idin your code and"@id/a_custom_id"in xmls. Of course its still pre-defined id (as opposed to runtime-defined id).