Question: I have more than 100 spinners in my xml. Is there any way to find all spinners without using findViewById() to all the 100 spinners? It's tedious and I don't mean by some creation tools or something like that, I mean if there is a code to solve this problem. I need to connect each spinner to a string-array from my array.xml file.

Answer: 
```
Spinner spinner;
LinearLayout layout  = (LinearLayout) findViewById(R.id.layout_id);
for (int i =0 ;i <layout.getChildCount(); i++){
    if(layout.getChildAt(i) instanceof Spinner){
            spinner = (Spinner) layout.getChildAt(i);
    }
}

```

Where LinearLayout is yours main layout which contains spinners. You can add spinner to list or do with it whatever you want.
This had troubled me as well. I adopted sergio91pt's method but found 0 spinners every time. Later I discovered the problem is that Spinner is an indirect subclass of ViewGroup. So when we do 

> 
> if (child instanceof ViewGroup)
> 
> 
> 

better to do one more check inside the if branch

> 
> if (!(child instanceof Spinner))
> 
> 
> 

so the code will be

```
private static void getAllSpinnersIn(ViewGroup view, List<Spinner> outList) {
    for (int i = 0, len = view.getChildCount(); i < len; i++) {
        View child = view.getChildAt(i);
        if (child instanceof ViewGroup) {
            if (!(child instanceof Spinner))
                getAllSpinnersIn((ViewGroup) child, outList);
        } else if (child instanceof Spinner) {
            outList.add((Spinner) child);
        }
    }
}

```