@@ -1352,24 +1352,23 @@ public View focusSearch(View focused, int direction) {
13521352 case ACCESSIBILITY_FOCUS_FORWARD : {
13531353 ViewRootImpl viewRootImpl = getViewRootImpl ();
13541354 if (viewRootImpl == null ) {
1355- break ;
1355+ return null ;
13561356 }
13571357 View currentFocus = viewRootImpl .getAccessibilityFocusedHost ();
13581358 if (currentFocus == null ) {
1359- break ;
1359+ return super . focusSearch ( this , direction ) ;
13601360 }
13611361 // If we have the focus try giving it to the first child.
13621362 if (currentFocus == this ) {
1363- final int firstVisiblePosition = getFirstVisiblePosition ();
1364- if (firstVisiblePosition >= 0 ) {
1363+ if (getChildCount () > 0 ) {
13651364 return getChildAt (0 );
13661365 }
1367- return null ;
1366+ return super . focusSearch ( this , direction ) ;
13681367 }
13691368 // Find the item that has accessibility focus.
13701369 final int currentPosition = getPositionForView (currentFocus );
13711370 if (currentPosition < 0 || currentPosition >= getCount ()) {
1372- break ;
1371+ return super . focusSearch ( this , direction ) ;
13731372 }
13741373 // Try to advance focus in the current item.
13751374 View currentItem = getChildAt (currentPosition - getFirstVisiblePosition ());
@@ -1386,25 +1385,31 @@ public View focusSearch(View focused, int direction) {
13861385 final int nextPosition = currentPosition - getFirstVisiblePosition () + 1 ;
13871386 if (nextPosition < getChildCount ()) {
13881387 return getChildAt (nextPosition );
1388+ } else {
1389+ return super .focusSearch (this , direction );
13891390 }
1390- } break ;
1391+ }
13911392 case ACCESSIBILITY_FOCUS_BACKWARD : {
13921393 ViewRootImpl viewRootImpl = getViewRootImpl ();
13931394 if (viewRootImpl == null ) {
1394- break ;
1395+ return null ;
13951396 }
13961397 View currentFocus = viewRootImpl .getAccessibilityFocusedHost ();
13971398 if (currentFocus == null ) {
1398- break ;
1399+ return super . focusSearch ( this , direction ) ;
13991400 }
14001401 // If we have the focus do a generic search.
14011402 if (currentFocus == this ) {
1403+ final int lastChildIndex = getChildCount () - 1 ;
1404+ if (lastChildIndex >= 0 ) {
1405+ return getChildAt (lastChildIndex );
1406+ }
14021407 return super .focusSearch (this , direction );
14031408 }
14041409 // Find the item that has accessibility focus.
14051410 final int currentPosition = getPositionForView (currentFocus );
14061411 if (currentPosition < 0 || currentPosition >= getCount ()) {
1407- break ;
1412+ return super . focusSearch ( this , direction ) ;
14081413 }
14091414 // Try to advance focus in the current item.
14101415 View currentItem = getChildAt (currentPosition - getFirstVisiblePosition ());
@@ -1422,7 +1427,7 @@ public View focusSearch(View focused, int direction) {
14221427 if (nextPosition >= 0 ) {
14231428 return getChildAt (nextPosition );
14241429 } else {
1425- return this ;
1430+ return super . focusSearch ( this , direction ) ;
14261431 }
14271432 }
14281433 }
0 commit comments