Axonshi 123
Axonshi 123

Reputation: 123

Create/Generate R.id on API level 16

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.

Upvotes: 0

Views: 480

Answers (2)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

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 .

Upvotes: 1

SaravInfern
SaravInfern

Reputation: 3388

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

Upvotes: 0

Related Questions