开发者

How to find a view in a class extended from Fragment?

开发者 https://www.devze.com 2023-03-26 19:16 出处:网络
How to find a view in a class extended from Fragment or ListFragmen开发者_运维知识库t? If I try

How to find a view in a class extended from Fragment or ListFragmen开发者_运维知识库t? If I try

Button newItemBtn = (Button)getView().findViewById(R.id.bt_add_item);

I do not receive my view back, meaning it was just not found. How to find it?


android fragment docs states :

 View listView = getActivity().findViewById(R.id.list);


The answer is that you have to do it in onActivityCreated() method, not in onCreate().

0

精彩评论

暂无评论...
验证码 换一张
取 消