java.lang.IllegalArgumentException: parameter must be a desc

异常信息:

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

错误原因:

发生这个错误主要是ListView或者其它ViewGroup等容器控件因为滑动而暂时移除子View,但却没有移除该子View上面的焦点Focus,所以在ListView滑动返回到原来的位置的时候没有恢复成原来的View,导致了该异常的产生,具体的源码分析可以查看参考链接[2]

解决方法:

解决办法就是清除掉ListView中item的焦点即可,下面是来自参考链接[1]的解决问题的代码:

{(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {// do nothing }(AbsListView view, int scrollState) {if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {View currentFocus = getCurrentFocus();if (currentFocus != null) {currentFocus.clearFocus();}}}}

这段代码是给ListView设置ScrollListener监听,使得ListView在滚动的时候可以清除掉ChildView中获取的焦点,大家也可以参考下参考链接[1]中其他的解决方法,我的代码中出现这个问题是因为我的ListView中inflate了一个HeaderView,这个HeaderView中有一个EditText输入框,,并且这个EditText获取到了焦点,所以我的ListView在向下滚动然后再返回到ListView顶部的时候会出现这个异常,我的解决办法就比较简单了,直接移除HeaderView中EditText的焦点就行了(mEditText.clearFocus();)。

参考链接:

自己打败自己的远远多于比别人打败的。

java.lang.IllegalArgumentException: parameter must be a desc

相关文章:

你感兴趣的文章:

标签云: