[英]Get the view of a Fragment outside of OnCreateView() - View is null
Inside onCreateView i can instance View with the inflate, in this way:在 onCreateView 中,我可以通过这种方式使用 inflate 实例化 View:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment if(savedInstanceState == null) { v = inflater.inflate(R.layout.fragment_my_team, container, false); setUpRecyclerView(v); } return v; }
Now, if launch a second activity when return in the first activity, in this fragment, the View is null because onCreateView it's already called.现在,如果在第一个活动返回时启动第二个活动,在这个片段中,视图是 null 因为 onCreateView 它已经被调用。 I don't know a to instance the view.
我不知道实例化视图。
Is there a solution of that?有解决办法吗?
Get rid of the if(savedInstanceState == null)
validation and create & return your view every time onCreateView
is invoked.摆脱
if(savedInstanceState == null)
验证并在每次调用onCreateView
时创建并返回您的视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.