美文网首页安卓开发
自定义View中使用findViewById时返回NULL问题的

自定义View中使用findViewById时返回NULL问题的

作者: 手指乐 | 来源:发表于2019-08-27 11:40 被阅读0次

今天碰到一个findViewById查找自定义view时返回NULL的问题,经过排查发现是构造函数调用错误:

public QiuQianAnimationView(Context context, AttributeSet attrs) {  
super(context);
    } 

QiuQianAnimationView这个自定义view中,调用父类的构造函数没有传入AttributeSet

改为:

public QiuQianAnimationView(Context context, AttributeSet attrs) {  
super(context,attrs);
    } 

即可

相关文章

网友评论

    本文标题:自定义View中使用findViewById时返回NULL问题的

    本文链接:https://www.haomeiwen.com/subject/kiosectx.html