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

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

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



        
18条回答
  •  星月不相逢
    2020-11-28 11:33

    In my case findViewById was returning null because my custom view looked something like this in the main XML:

            
    

    and I found out that when I added the xmlns stuff it worked like this:

            
    

提交回复
热议问题