Daniel Kaplan
Daniel Kaplan

Reputation: 721

Understanding resource values in Android

I may be twisting things because my last programming was Windows in C. But am trying to find "where" in android apps a resource such as an icon is assigned a value and where it's referenced in code.

Am doing my best to find it now, but can't.

Maybe I am misunderstanding the way "resources" work in Android?

Thanks ahead,

Sergio

Upvotes: 0

Views: 39

Answers (1)

Francesc
Francesc

Reputation: 29260

When you compile your app, a class called "R" is generated. This references all your resources (strings, drawables, layouts, ...). Each resource is assigned an integer value.

In code, you would reference that resource through the "R" class, for instance:

Image: R.drawable.my_drawable
String: R.string.hello_world
Layout: R.layout.my_layout

and so on. As a concrete example, you would have

String text = getString(R.string.hello_world);

Upvotes: 1

Related Questions