FindViewById where ID is dynamic string

前端 未结 3 1729
甜味超标
甜味超标 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:38

    You can get an identifier from a string by using:

    notes = (TextView)findViewById(getResources().getIdentifier(VIEW_NAME, "id", getPackageName()));
    

    Where VIEW_NAME is whatever identifier string you're generating. After that, you can set the text of it like you currently are. This also works if you need to get strings and drawables as well, just change id to the appropriate type.

提交回复
热议问题