我的主要目标是通过触摸式探索了解listView中哪个项目的重点是辅助功能焦点。
因为我正在处理某个应用程序,所以我无法访问此行为的辅助功能服务方法。
最好的办法是拥有像onItemClickListener一样的onItemHoverListener:
listView.setOnItemHoverListener(new OnItemHoverListener(){
public void onItemHover(AdapterView<?> parent, View v, int position, long id)
{
//Can know here which item is focused by Explore by touch
//Can get the position of this item in my listview
}
});
我还能做些什么来解决这个问题?
答案 0 :(得分:0)
您可以通过在父视图上覆盖onRequestSendAccessibilityEvent或在覆盖此方法的父视图上设置AccessibilityDelegate来观察TYPE_VIEW_ACCESSIBILITY_FOCUSED事件来观察辅助功能焦点更改。
myListView.setAccessibilityDelegate(new MyDelegate());
将委托定义为:
class MyDelegate extends AccessibilityDelegate {
...
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
AccessibilityEvent event) {
if (host == myListView) {
int childPosition = myListView.getPositionForView(child);
...
}
}
}