开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜