Android: can get custom R.id file

Is it possible to get android to give me a user id?

so for example if i already 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 access as

R.id.a_custom_id 
+5
source share
2 answers

You cannot dynamically create new identifiers. Even if you Rwere able to do this, you will not be able to access it using R.id.a_custom_id. Java is not a dynamic language and cannot add fields at run time.


However, there is a solution for compilation. In res/values/ids.xmladd:

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <item type="id" name="a_custom_id"/>
</resources>

R.id.a_custom_id "@id/a_custom_id" xmls. , id ( , ).

+16

All Articles