Pregunta

I need to get the first Button in the layout, in order to request focus dynamically.

Is there any function that allow me to resolve my problem ?

¿Fue útil?

Solución

Check out about the ViewGroup class.

This should do the trick:

for(int i=0 ; i<((ViewGroup) layout).getChildCount() ; i++) {
    if(((ViewGroup) layout).getChildAt(i) instanceof Button) {
        // Here is your first Button!
    }
}

EDIT : I just added ViewGroup casts to my answer, just in case the implicit conversion would raise a ClassCastException.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top