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

复现:

当ListView的item中有Edittext,并且已经调起了软键盘的时候,去滑动ListView会出现该异常导致APP crash

原因:

发生这个错误主要是ListView或者其它ViewGroup等容器控件因为滑动而暂时移除子View,但却没有移除该子View上面的焦点Focus,所以在ListView滑动返回到原来的位置的时候没有恢复成原来的View,导致了该异常的产生

解决:

在开始滑动的时候清除当前的焦点就可以了

public class CleanFocusScrollListener implements AbsListView.OnScrollListener {
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {

            View currentFocus = null;
            if (view.getContext() instanceof Activity) {
                currentFocus = ((Activity) view.getContext()).getCurrentFocus();
            }
            if (currentFocus != null) {
                currentFocus.clearFocus();
            }
        }
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

    }
}

你可能感兴趣的:(java.lang.IllegalArgumentException: parameter must be a descendant of this view)