findViewById returns NULL when using Fragment

前端 未结 7 1874
终归单人心
终归单人心 2020-12-14 16:15

I\'m new to Android developing and of course on Fragments.

I want to access the controls of my fragment in main activity but \'findViewById\' returns null. without f

7条回答
  •  失恋的感觉
    2020-12-14 17:05

    You can't access the the view of fragment in activity class by findViewById instead what you can do is...

    You must have an object of Fragment class in you activity file, right? create getter method of EditText class in that fragment class and access that method in your activity.

    create a call back in Fragment class on the event where you need the Edittext obj.

提交回复
热议问题