0

This is my code simplified.

setOnClickListener
    _view = new View(MainActivity.this);
    _root.addView(_view);

I click, and a new view gets added. But i need to distinguish these view somehow. So i tired this.

_view.setId(View.generateViewId());

Unfortunatly this showed up.

Call requires API level 17 (current min is 16): android.view.View#generateViewId

Any suggestions are appreciated, thanks!

Edit: Sorry, should've said this before, I need it to be on API level 16.

Axonshi 123
  • 123
  • 2
  • 10
  • As stated here https://stackoverflow.com/a/15442898 you can use `ViewCompat.generateViewId()` if your app is targeted lower than API level 17. Otherwise use `View.generateViewId()`. – Bruno Bieri Jun 25 '20 at 06:47

2 Answers2

1

Call requires API level 17 (current min is 16): android.view.View#generateViewId

You should increase your API level .

 minSdkVersion 17// instead of 16

android:minSdkVersion

An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute.

I need it to be on API level 16.

setId(View.generateViewId()) used to identify the view . I think it will be better if you set level 17 .

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

instead of View.generateViewId() you can use view.settag(int) to uniquely identify your view and get the view's tag using view.getTag()

SaravInfern
  • 3,338
  • 1
  • 20
  • 44