Android: programmatically setId gives warning Expected resource identifier type

I do not know why this is happening:

If I write the following code:

TextView textView = new TextView(this);
textView.setId(1);

1 , since id is not working and gives me a warning:

enter image description here

It does not work in the following values:

textView.setId(0+1);   // Valid
textView.setId(var++); // Valid even var=0

but not valid

textView.setId(1);     // Invalide

Does anyone know about this? Can anyone explain this?

+4
source share
2 answers

This warning is generated by android lint . It verifies that you are using the correct type of identifier as the identifier. Signature for this function:

public void setId(@IdRes int id)

, lint , @IdRes (. IdRes), @ColorRes @StringRes ( , R.id)

0+1 var++ (BTW, 0 1), .

+1

, , , , , xml, , , . View.generateViewId() .

0

All Articles