Frage

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 ?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top