The 'Compat' library now also supports the generateViewId()
method for API levels prior 17.
Just make sure to use a version of the Compat
library that is 27.1.0+
For example, in your build.gradle
file, put :
implementation 'com.android.support:appcompat-v7:27.1.1
Then you can simply use the generateViewId()
from the ViewCompat
class instead of the View
class as follow:
//Will assign a unique ID
myView.id = ViewCompat.generateViewId()
Happy coding !