Is it a good thing to write logic based on the hex value of id generated in R.java android

前端 未结 2 733
悲&欢浪女
悲&欢浪女 2021-01-29 08:17

This what I have seen in an android application. They have a number of image buttons with ids

R.java :
        public static final int img1=0x7f090080;
        p         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-29 08:42

    Though this might work OK most of the times, this is definitely not advisable. The R class is generated automatically thus you have no control over it and it could change. There is a solution to this problem using a typed array in resources. Check for example this answer.

提交回复
热议问题