What is the concept behind R.java?

后端 未结 4 928
孤独总比滥情好
孤独总比滥情好 2020-12-01 13:29

In android R.java is used to provide access to resources defined in XML files. To access the resource we need to invoke findViewById() method passing in the id

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 14:11

    android.R.java is not just where XML ids are stored. It also contains access to resources - such as drawables, layouts, strings, arrays, and basically anything you can declare in resources.

    Personally I find that it is useful when using Eclipse. I can simply type findViewById(R.id. and Eclipse will show a tooltip with a list of options to choose from.

    However at a platform level, I would say that the hardcoded id variables help prevent errors when using Strings to identify resources -- something that can be debuggable while programming (or during compilation, rather than runtime).

提交回复
热议问题