findViewById() returns null for custom component in layout XML, not for other components

前端 未结 18 1504
情歌与酒
情歌与酒 2020-11-28 10:36

I have a res/layout/main.xml including these elements and others:



        
18条回答
  •  庸人自扰
    2020-11-28 11:28

    I have the same problem because in my custom view I overrided constructor but invoked super contructor withot attrs paramete. That is copy paste)

    My previous constructor version:

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

    Now I have:

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

    And that works!

提交回复
热议问题