Can not resolve method 'findViewById(int)'

前端 未结 9 843
孤城傲影
孤城傲影 2021-02-05 03:08

I\'m having a trouble with findViewByid but I can\'t find where the problem is.

Here\'s my FirstFragment class code:

import and         


        
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 03:29

    Fragment doesn't provide thefindViewById() method. This is provided in Activity or View. When implementing a Fragment you don't inflate your views in onCreate() (like you normally do in an Activity.) Instead, you do it in onCreateView() and you need to use the inflated root View to find the ID within the layout you inflated.

提交回复
热议问题