Java. lang. IllegalArgumentException: parameter must be a descendant of this view, descendant
Exception information:
Java. lang. IllegalArgumentException: parameter must be a descendant of this view
Error cause:
This error occurs mainly because the container control, such as ListView or other ViewGroup, temporarily removes the child View because of sliding, but does not remove the Focus on the child View, therefore, the original View is not restored when the ListView slides back to the original position, resulting in the exception. For details about the source code analysis, refer to [2].
Solution:
The solution is to clear the focus of the item in the ListView. The following is the code for solving the problem from the reference link [1:
protected class MyScrollListener implements OnScrollListener { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // do nothing } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (SCROLL_STATE_TOUCH_SCROLL == scrollState) { View currentFocus = getCurrentFocus(); if (currentFocus != null) { currentFocus.clearFocus(); } } } }
This Code sets a ScrollListener listener for the ListView so that the ListView can clear the focus obtained in the ChildView when scrolling. You can also refer to other solutions in [1, this problem occurs in my code because a HeaderView is inflate in my ListView. This HeaderView contains an EditText input box and the EditText gets the focus, so this exception occurs when my ListView is scrolling down and then returning to the top of the ListView. My solution is simple, directly remove the EditText focus in HeaderView (mEditText. clearFocus ();).
Reference link:
Http://stackoverflow.com/questions/7100555/preventing-catching-illegalargumentexception-parameter-must-be-a-descendant-of
Http://blog.sina.com.cn/s/blog_5704bfaf0102v3bn.html
Http://www.cnblogs.com/LIANQQ/p/4026560.html
Http://www.educity.cn/wenda/100840.html
Http://blog.csdn.net/a443453087/article/details/8079990
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.