Android: drawable resource with numbers. Is it possible?
Asked Answered
P

3

6

I would like to know if i can, somehow, create a drawable resource (png for example) called 787.png. Because Eclipse wont let me compile the project unless i modify it.

Thanks in advance.

Player answered 17/8, 2011 at 17:23 Comment(0)
S
14

The reason you can't have a resource with a numeric name is because variable names cannot start with numbers. For each resource, there is a generated constant variable (in R.java) with the resource's name. If you look in your Eclipse project, under the "gen" folder you will see R.java

It is my understanding that it is not possible to have a resource with a pure numeric name in an android project.

If you explain why you require a numeric resource, maybe we can provide alternative solutions

Sounder answered 17/8, 2011 at 17:26 Comment(2)
What i do is i get some data from some webpages. Then, to show it on my app, some icons for example, are drawables that i have as resources. The reasson to name a resource with numeric values is because i use the same string i get from the web. If i get the string "icon2" from the web, ill have an icon2.png as a resource. I could do it another way, sure. Change the "787" string i get from the web, for "seveneightseven". But i wanted to know if it could be done somehow. But seems its not possible. Thanks for the help.Player
@Player just prefix the images in the android app with something, and append the number to it. so if the server says "show image 787", the android app will look for image named "my_prefix_787"Sounder
D
0

Short Answer is NO, Drawable resource image name must be start character
Like as R.drawable.abc. // right R.drawable.123 //wrong

Dactylo answered 6/5, 2020 at 11:24 Comment(1)
Amit, please be sure to read the existing answers before contributing your own—and especially if the question already has an accepted answer. In this case, the accepted answer from nine years ago effectively says the same thing, albeit with more detail. As such, this isn't contributing much to the post outside of being more succinct.Mallet
C
0

So you can NOT have a drawable that starts with a number , ex: 49ers BUT you can have this _49ers which is expectable.

Cordero answered 15/9, 2024 at 22:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.