findViewById not working for an include?

后端 未结 7 1299
终归单人心
终归单人心 2020-11-27 06:05

I have an include like:


The include layout looks like (te

7条回答
  •  醉酒成梦
    2020-11-27 06:27

    I had the same problem. I found out that I used a wrong function with the same name with 2 parameters as following:

    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.activity_ble_connecting);
        //findViewByid() => wrong
    } 
    

    correct function with only one parameters:

        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_ble_connecting);
            //findViewByid() => correct
        }
    

提交回复
热议问题