Answer the question
In order to leave comments, you need to log in
How does the MainActivity class and activity_main.xml interact?
How is the R class created, how is it associated with activity_main.xml? As I understand it, on the basis of activity_main.xml, an object is created with child objects defined in it .. but how is it done and what software.
How are handlers defined in MainActivity linked to handler names in activity_main.xml? It is not explicitly stated, just the name of the handler is specified in the xml attribute of the object.
How does this magic work? Or where can I read about it?
Answer the question
In order to leave comments, you need to log in
As usual, you can read such things in the documentation:
About resources: https://developer.android.com/guide/topics/resource...
About accessing resources: https://developer.android.com/guide/topics/resource ...
The R class is generated by the aapt tool (Android Asset Packaging Tool). R contains identifiers for the corresponding resources, which you can then use in your code (for example, findViewById). It binds MainActivity and activity_main.xml via setContentView(R.layout.activity_main) call. setContentView has two overloads, one to call with a View object to set a specific object to represent the UI of this Activity, and the other to call with an int to set the layout ID of the resource, which is then inflated. inflate is, as you can easily imagine, the process of creating a View hierarchy according to data from a resource file with layout, descendants of the abstract LayoutInflater class are engaged in this process, in fact, it can bind handlers and everything else.
You can also search your project for the generated R.java file and view it.
How an R class is created
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question