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

Posted 小哇壁纸

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java.lang.IllegalArgumentException: parameter must be a descendant of this view相关的知识,希望对你有一定的参考价值。

Log信息

java.lang.IllegalArgumentException: parameter must be a descendant of this view
    at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4555)
    at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:4492)
    at android.view.ViewRootImpl.scrollToRectOrFocus(ViewRootImpl.java:2659)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2303)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2252)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1882)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:999)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5663)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
    at android.view.Choreographer.doCallbacks(Choreographer.java:587)
    at android.view.Choreographer.doFrame(Choreographer.java:557)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5345)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:855)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:671)
    at dalvik.system.NativeStart.main(Native Method)

bug出现的情况:Android系统4.4.2和4.4.4,在Listview适配子项中存在edittext编辑框,并且数据是超出一屏 。当即点击最后一项中的edittext弹出了软键盘 然后收缩父项后就出现异常。

 

解决方法

public View getView(int position, View convertView, ViewGroup parent) {
    //强制清除当前焦点
    Activity activity = (Activity) getContext();
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        currentFocus.clearFocus();
    }
}

 

以上是关于java.lang.IllegalArgumentException: parameter must be a descendant of this view的主要内容,如果未能解决你的问题,请参考以下文章

IllegalArgumentException:此 NavController 未知导航目的地 xxx