Java. lang. IllegalArgumentException: parameter must be a descendant of this view, descendant

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.