I’m trying to access all EditText
which have been creating programmatically according to an array. As you know Java has getComponents()
method which returns array of the components and which allows you to use enhanced for loop like below:
for(Component c : parent.getComponents()){
if(c instanceof TextField){
...
}
}
Normally I was using getChildCount()
and getChildAt(int index)
together:
for(int i = 0; i < parent.getChildCount(); i++){
if(parent.getChildAt(i) instanceof EditText){
...
}
}
While I was reading documentation and I saw getTouchables()
method. From documentation:
Find and return all touchable views that are descendants of this view, possibly including this view if it is touchable itself
So I tried enhanced for loop with that method:
for(View v : parent.getTouchables()){
if(v instanceof EditText){
...
}
}
Above loop also works so I decided to search on the internet about getTouchables()
method for getting more information but couldn’t able to find anything. I saw this question but from answers only this answer suggests alternative method (getFocusables(int direction)
) than using getChildCount()
and getChildAt(int index)
methods together.
For better understanding if we think about only EditText which one (getTouchables()
vs. getFocusables(int direction)
vs. getChildCount()
& getChildAt(int index)
together) is more suitable?