小马哥
小马哥

Reputation: 21

AccessibilityService Listview item click or Analog enter event?

I'm trying to traverse the ListView, to implement the click event to each item, but does not work. please Why clicking has no effect?

public void addFriendSearch(AccessibilityNodeInfo info) {

        try {


                L.i(TAG, "-addFriendSearch-parent widget----------------------------" + info.getClassName());
                L.i(TAG, "--Text:" + info.getText());
                L.i(TAG, "--windowId:" + info.getWindowId());
                boolean contentInvalid = info.isVisibleToUser();
                L.i(TAG, "--contentInvalid:" + contentInvalid);

                for (int i = 0; i < info.getChildCount(); i++) {
                    AccessibilityNodeInfo child = info.getChild(i);
                    boolean equals = child.getClassName().equals("android.widget.ListView");
                    if(equals){
                        for (int j = 0; j < child.getChildCount(); j++) {
                            L.i("listview child:"+j);
                            AccessibilityNodeInfo child1 = child.getChild(j);
                            if (child1 != null) {
                                if (child1.isClickable()) {
                                    L.i("listview child click");
                                    info.performAction(AccessibilityNodeInfo.ACTION_CLICK); // click
                                }
                            }
                        }

                    }else{
                        if(child!=null){
                            addFriendSearch(info.getChild(i));
                        }
                    }

                }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

or How to enter the event?

Upvotes: 2

Views: 799

Answers (1)

user2738475
user2738475

Reputation: 11

In 'info' you are having the handle to the complete parent widget but you are trying to click on a specific element. You would have to access specific child element using the 'child1' to be able to click on the specific element.

Change

info.performAction(AccessibilityNodeInfo.ACTION_CLICK);

to

child1.performAction(AccessibilityNodeInfo.ACTION_CLICK);

This will ensure the click action is performed on specific sub element and not the complete widget, which is the reason it is not working currently.

Upvotes: 1

Related Questions