FindViewById where ID is dynamic string

前端 未结 3 1719
甜味超标
甜味超标 2020-12-16 13:58

I have a table of 40 squares and each has an ID. When I\'m passing Bundle from another activity I need to extract Note, Color and ID from that bundle. And then the app will

3条回答
  •  暖寄归人
    2020-12-16 14:30

    Assuming you're passing in the actual string "R.id.passed_id", I would recommend passing in the integer value instead. Thus, simply pass in R.id.passed_id.

    All values in the R file of an application are simply integers that are mapped to resource locations. The findById() methods are only looking for integers, so if you start the Activity and pass in the integer value of the resource you want, it will find it.

    Note: This will only work if the resources are within the same application. R files remain constant for an application, but they can change from one app to another even if they have the same name. If, however, the two activities fall under the same application package, it will work.

提交回复
热议问题