1
It is possible to reference several elements at one time?
Ex:
An array with all tags and another with Edittext:
public class Main extends AppCompatActivity {
String[] tags = {"edit1", "edit2", "edit3"};
//Um array de edittext, creio não ser possível, mas é só para o exemplo
EditText[] editText = {edit1, edit2, edit3};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//E então fizer
for (int i = 0; tags.length < i; i++){
editText[i].findViewWithTag( tags[i] );
}
//Assim fazendo referencia a todos editText com um for
}
}
Is there any way to do that? Remembering, this example above the way I did is not possible, I know, is because I have more than 20 Edittexts in a layout, and I wanted a simpler way to reference all.
If there is a way with findViewById, it may be too, but I think that with findViewWithTag is easier
Can’t declare the names directly from the array no? More or less like I did in my example Edittext[] editText = {edit1, edit2, edit3};
– Woton Sampaio
Not because you don’t have the references. To use this way you would have to have an Edittext type variable for each of them and get their references, using
findViewById()
, before you can use them ineditText = {edit1, edit2, edit3};
– ramaral