Tried to use, did not work. Can you please tell us how to use such a structure?
- What is it used for? In your case? - P. Ilyin
- The argument must be an integer of type int. In this case, if it coincides with the number from the class R, then you will have problems. Class R is generated automatically and you cannot write something there. Why do I need to reassign the ID? - pavlofff
- What do you mean by "not working"? - xkor
2 answers
According to the documentation
Sets the identifier for this view. This identifier does not have to be unique in this view's hierarchy. The identifier should be a positive number.
That is, you can set any positive integer as id and its uniqueness is not required.
In your case, it turns out that you are trying to associate editText c id, which is already in the class R and there is a View that has this id set. So when you call findViewById (), the view that was first found in the current hierarchy of the view-elements will return to you, and it’s not a fact that this will be the editText you need. To avoid this, it is necessary for the view that was associated with myid to editText to change the id to another
Starting from API 17, you can use the method
public static int generateViewId ()
Generate a value of setId (int). This is not a match for ID values generated at build time for R.id.
editText = (EditText) findViewById(R.id.myId) Find the item by ID .
I think setId() needed to assign an ID element .
- Well, yes, I want to reassign id. - Lord Bomge