Вопрос

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 ?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top