I'm trying to create a RelativeLayout
with several children programmatically. To make the rules like RelativeLayout.RIGHT_OF
work, the child views must have proper IDs.
However, when I try to assign an ID, Android Studio flags it as an error:
view.setId(123);
ERROR: Expected resource of type id
找到了:
view.setId(View.generateViewId());
You have two options:
In Android Studio click on lightbulb on line with this 'error'. And select 'Disable inspection' in first submenu.
As others have said, you shouldn't be using Integers directly in this case. There are some very rare cases where you might need to do this or in general suppress validation warnings. If so then you need to look into Lint . In Android Studio you can click on the red light bulb at the left side of the line of code. This will show a context menu with a list of methods of suppression.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.