简体   繁体   中英

Android accessibility - is there a way to detect if talk back is reading content description

I've got a ListView that's gets populated with data from the server (phone numbers) and I'm polling every 2 seconds. When TalkBack feature is switched on and the I tap on a list item, the talkBack doesn't get the chance to read the whole string because the refresh occurs and the talkBack starts from the begging. Is there a way to detect if the TalkBack if content description is being read? Thank you.

ListView relies on the value of Adapter.hasStableIds() to determine if inflated views can be reused across data set changes.

If this method returns false , ListView assumes that there is no consistency between the data set before and after a change. As a result, it doesn't know where accessibility focus should be placed.

However, if this method returns true and your adapter maintains a consistent mapping between item ID and data, then ListView is able to maintain accessibility focus on the correct item -- even if it changes position within the data set.

To fix this issue, you can modify your adapter to maintain stable IDs:

class MyAdapter extends ListAdapter {
    ...

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public long getItemId(int position) {
        // Return a consistent mapping between the item at a given
        // position and an arbitrary (but consistent!) ID associated
        // with that item.
        ...
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM