Code example for AccessibilityNodeInfo

Methods: setCheckable, setChecked, setText

0
        public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
            super.onInitializeAccessibilityNodeInfo(info);
            // We called the super implementation to let super classes set 
            // appropriate info properties. Then we add our properties 
            // (checkable and checked) which are not supported by a super class. 
            info.setCheckable(true);
            info.setChecked(isChecked());
            // Very often you will need to add only the text on the custom view. 
            CharSequence text = getText();
            if (!TextUtils.isEmpty(text)) {
                info.setText(text);
            } 
        } 
 
        @Override 
        public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
            super.onPopulateAccessibilityEvent(event);
            // We called the super implementation to populate its text to the 
            // event. Then we add our text not present in a super class. 
            // Very often you will need to add only the text on the custom view. 
            CharSequence text = getText();