0
I have an interaction and within it create several EditText
dynamically, but how to keep the id for each EditText
?
My code:
for (int j = 0; j < vet.length; j++) {
EditText nome = new EditText(this);
nome.setId(0+x);
EditText sobrenome = new EditText(this);
sobrenome.setId(1+x);
x = x+2;
}
I tried this logic, but realized that its the size of my vector is 3 for example, creates 3 pairs of EditText
(name + surname), but the 3 pairs have the same id, which makes sense, and I needed to at least know if I clicked on the first name, 2nd or 3rd.
Nor with the onClick()
I can differentiate the "names".
Note: I am putting all these Edittexts in one LinearLayout
, if it were in a ListView
I could take the position at least.
Do you know any Android method to achieve this? Thanks in advance.
I don’t understand when you say that the 3 pairs get the same id.
– ramaral
I expressed myself badly, it actually looks like this: name:4 surname:5; surname:4 surname:5; surname:4 surname:5;
– daniel12345smith
By what I see in the code they should all be different. The only thing left is to initialize variable x:
int x = 1;
– ramaral
I start out of for, but I think it gets the same id because Edittext has the same name, so even those that have already been created get the value of the last id.
– daniel12345smith
I really needed to differentiate the names in some way. In Listview a simple getItem(Position) would work.
– daniel12345smith
Where are they added to Linearlayout?
– ramaral
I’m playing inside a single Linearlayout that sits inside a scrollView, very simple structure.
– daniel12345smith