문제

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