简体   繁体   English

在 OnCreateView() 之外获取片段的视图 - 视图为 null

[英]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.

相关问题 如何获取OnCreateView()之外的片段视图 - How to get the view of a Fragment outside of OnCreateView() 片段中的findViewById,如何在onCreateView之外获取视图 - findViewById in fragment , how to get view outside onCreateView 在OnCreateView调用之外将视图动态添加到片段 - Dynamically Add View To Fragment Outside OnCreateView Call Android-片段视图在onCreateView之外获取NULL - Android - Fragment Views get NULL outside onCreateView 在DrawerItemClickListener(NavigationDrawer)中访问片段的视图-onCreateView()之外 - Access fragment's view in DrawerItemClickListener (NavigationDrawer) - outside onCreateView() 在我的滑动视图选项卡项目的片段中获取空的“ onCreateView ..((bundle savedInstanceState)”) - Get null “onCreateView..(Bundle savedInstanceState)” in fragment my swipe view tab project 无法访问onCreateView()之外的视图 - Unable to access view outside onCreateView() 在Fragment.OnCreateView()之外获取片段活动 - Get fragment activity outside of Fragment.OnCreateView() 在片段完成onCreateView之前从ViewPager获取视图 - Get view from ViewPager before fragment finishing onCreateView 片段中onCreateView方法之外的上下文更改为null - Context changes to null outside of onCreateView method in a fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM