What's "R" in kotlin/android studio?

Viewed 3286

So I started watching an android development using kotlin course. The guy explaining uses "R" without explaining anything about it. I tried searching the documentation but could not find anything.

here is a sample code:

    when(...) { ...
        R.id.btn9 -> btnID=9 // where btn9 is an id of a button in the UI
    }
2 Answers

R is a class generated automatically by the tools that build your project. It will contain ids from the XML resource files. E.g. there will be a constant per each resource file and per each id in every XML layout. You can find more information about the class in Android docs in here.

The R.java file creates an object with resource IDs for all of the resources your application uses. This includes drawables, layouts, strings, arrays, etc. When you need to access any resource, you can use R to locate and connect to it rather than hard coding the resource IDs throughout your program.

Related