我是Android的新手,当屏幕方向改变时,我就面临着这个问题。每当屏幕方向改变时,fragment
会被调用两次。下面是我的代码示例。我检查了其他帖子,但找不到答案。任何人都可以指导我。
public class SampleFragment extends Fragment {
static final String TAG_NAME = SampleFragment.class.getSimpleName();
List<PhrToolBar> mToolBarList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
DaggerHelper.getAppProviderComponent().inject(this);
mRootView = null;
getActivity().setTitle("Personal Health Records");
mRootView = inflater.inflate(R.layout.sample_phr_main_fragment, container, false);
mBinding = DataBindingUtil.bind(mRootView);
mBinding.setViewModel(mViewModel);
setHasOptionsMenu(true);
return mRootView;
}
1条答案
按热度按时间egdjgwm81#
将以下代码添加到Activity的
onCreate
方法中: