@@ -1456,7 +1456,7 @@ public void sendAccessibilityEvent(int eventType) {
14561456 final int lastVisiblePosition = getLastVisiblePosition ();
14571457 if (mLastAccessibilityScrollEventFromIndex == firstVisiblePosition
14581458 && mLastAccessibilityScrollEventToIndex == lastVisiblePosition ) {
1459- return ;
1459+ return ;
14601460 } else {
14611461 mLastAccessibilityScrollEventFromIndex = firstVisiblePosition ;
14621462 mLastAccessibilityScrollEventToIndex = lastVisiblePosition ;
@@ -2278,28 +2278,37 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo i
22782278 super .onInitializeAccessibilityNodeInfo (host , info );
22792279
22802280 final int position = getPositionForView (host );
2281+ final ListAdapter adapter = getAdapter ();
2282+
2283+ if ((position == INVALID_POSITION ) || (adapter == null )) {
2284+ // Cannot perform actions on invalid items.
2285+ info .setEnabled (false );
2286+ return ;
2287+ }
22812288
2282- if (position == INVALID_POSITION ) {
2289+ if (!isEnabled () || !adapter .isEnabled (position )) {
2290+ // Cannot perform actions on invalid items.
2291+ info .setEnabled (false );
22832292 return ;
22842293 }
22852294
2286- if (isClickable () && isEnabled ()) {
2295+ if (position == getSelectedItemPosition ()) {
2296+ info .setSelected (true );
2297+ info .addAction (AccessibilityNodeInfo .ACTION_CLEAR_SELECTION );
2298+ } else {
2299+ info .addAction (AccessibilityNodeInfo .ACTION_SELECT );
2300+ }
2301+
2302+ if (isClickable ()) {
22872303 info .addAction (AccessibilityNodeInfo .ACTION_CLICK );
22882304 info .setClickable (true );
22892305 }
22902306
2291- if (isLongClickable () && isEnabled () ) {
2307+ if (isLongClickable ()) {
22922308 info .addAction (AccessibilityNodeInfo .ACTION_LONG_CLICK );
22932309 info .setLongClickable (true );
22942310 }
22952311
2296- if (isEnabled ()) {
2297- info .addAction (AccessibilityNodeInfo .ACTION_SELECT );
2298- }
2299-
2300- if (position == getSelectedItemPosition ()) {
2301- info .setSelected (true );
2302- }
23032312 }
23042313
23052314 @ Override
@@ -2309,22 +2318,33 @@ public boolean performAccessibilityAction(View host, int action, Bundle argument
23092318 }
23102319
23112320 final int position = getPositionForView (host );
2321+ final ListAdapter adapter = getAdapter ();
23122322
2313- if (position == INVALID_POSITION ) {
2323+ if ((position == INVALID_POSITION ) || (adapter == null )) {
2324+ // Cannot perform actions on invalid items.
23142325 return false ;
23152326 }
23162327
2317- if (!isEnabled ()) {
2328+ if (!isEnabled () || !adapter .isEnabled (position )) {
2329+ // Cannot perform actions on disabled items.
23182330 return false ;
23192331 }
23202332
23212333 final long id = getItemIdAtPosition (position );
23222334
23232335 switch (action ) {
2336+ case AccessibilityNodeInfo .ACTION_CLEAR_SELECTION : {
2337+ if (getSelectedItemPosition () == position ) {
2338+ setSelection (INVALID_POSITION );
2339+ return true ;
2340+ }
2341+ } return false ;
23242342 case AccessibilityNodeInfo .ACTION_SELECT : {
2325- setSelection (position );
2326- return true ;
2327- }
2343+ if (getSelectedItemPosition () != position ) {
2344+ setSelection (position );
2345+ return true ;
2346+ }
2347+ } return false ;
23282348 case AccessibilityNodeInfo .ACTION_CLICK : {
23292349 if (isClickable ()) {
23302350 return performItemClick (host , position , id );
0 commit comments