Assign a view ID programmatically in Android

android, android-layout, android-studio

Solution

Found it:

view.setId(View.generateViewId());

Problem

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 ```

Original source

Related problems