Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How create resource id without a resource

I need to associate several tags to a view so I use

 view.setTag(id, tag_object)

Unfortunately Android requires to have the id as defined in a resource. However R file is auto generated of resource ids appearing in different resource files, so I do not know how to create an id detached from any resource. As work around I just use id of some resource but it isn't robust, because if I decide to remove the resource, the id can disappear. It is also reduces readability of the code having some weird id for addressing a tag. Perhaps I missed very simple trick as ids resource file.

like image 788
user2305886 Avatar asked Dec 23 '13 23:12

user2305886


People also ask

Where can I find resource ID?

Navigate to your storage account in the Azure portal. On the Overview page, in the Essentials section, select the JSON View link. The resource ID for the storage account is displayed at the top of the page.

What are the use of resource ID in Android?

All resource IDs are defined in your project's R class, which the aapt tool automatically generates. When your application is compiled, aapt generates the R class, which contains resource IDs for all the resources in your res/ directory. For each type of resource, there is an R subclass (for example, R.

What is the resource ID?

The Resource ID indicates the position of the resource in relation to other resources. How Calculated As you add resources, Project automatically assigns the next number in the sequence of resources as listed. This becomes the Resource ID. Best Uses The only view that the Resource ID field appears in is the Task Form.

How do I find my resource ID Android?

int resourceId = this. getResources(). getIdentifier("nameOfResource", "id", this.


1 Answers

There is a resource type "id" that lets you define arbitrary resource IDs:

http://developer.android.com/guide/topics/resources/more-resources.html#Id

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

Will generate R.id.foo and R.id.bar.

like image 91
Erich Douglass Avatar answered Sep 28 '22 03:09

Erich Douglass