Users are getting the following exception in my app on certain phones. I tried reproducing the error myself but couldn\'t . I searched through stack overflow for similar problem
I was also getting the same error when Google TalkBack is turned on. In my case, I was inflating a view with the boolean attachToParent true.So by making it false worked for me.
I have append on scroll listener in ScrollView and solve problem
lst_payment_info.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
View currentFocus = getCurrentFocus();
if (currentFocus != null) {
currentFocus.clearFocus();
}
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
The problem was caused by adding a wrongly inflated header to two different listviews.
I inflated a view using listViewA
as the parent and adding it to listViewB
also. As such:
RelativeLayout listViewHeader = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewA, false);
// Set some views
listViewA.addHeaderView(listViewHeader);
listViewB.addHeaderView(listViewHeader);
I fixed it by changing the above to the following:
RelativeLayout listViewHeaderA = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewA, false);
RelativeLayout listViewHeaderB = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewB, false);
listViewA.addHeaderView(listViewHeaderA);
listViewB.addHeaderView(listViewHeaderB);
As for reproducing the crash, the problem happened when Google Talk Back is turned on. Here is my take on the situation: Google Talk Back does text to speech on views that are in focus (either by touch or auto-focused). When it enters a screen with multiple views requesting focus, it reads the views according to a hierarchy/order.
If you have a layout (parent) with three views (children), Google Talk Back checks how the views are arranged and then reads them accordingly. For example, in a layout with three textview lined up horizontally, Google Talk Back may read the left textview first, then the middle one, then the one on the right.
In my case, I was inflating a header view with listViewA
as the parent and adding that view to both listViewA
and listViewB
. When listViewB
gains focus and Google Talk Back tries to interpret its children, it sees the header view is not a child of the list and throws the exception. This also happens if I inflate the header view with no parents (null).