Closed pishguy closed 7 years ago
Presenter is available only after onViewCreated() lifecycle callback (which is the next one after onCreateView () ). Don't forget to call super.onViewCreated() when overriding
Mahdi Pishguy notifications@github.com schrieb am Mi., 31. Mai 2017, 06:28:
when i trying to use this library to implementing mvp for fragments, i get null for getPresenter(),
public class FragmentCategories extends MvpViewStateFragment<UserCategoriesView, UserCategoriesPresenter, UserCategoriesViewState> implements UserCategoriesView {
@BindView(R.id.mainCategoriesFlipper) ViewFlipper mainCategoriesFlipper; @BindView(R.id.mainCategoryList) RecyclerView mainCategoryList; @BindView(R.id.categoryChildList) RecyclerView categoryChildList; @BindView(R.id.selectedChannelsList) RecyclerView selectedChannelsList; private Unbinder unbinder; private List<MainCategories> mainCategories; private List<ChildCategories> childCategories; private List<Channels> channelsList; private Activity activity; private Context context; private MainCategoryAdapter mainCategoryAdapter; private ChildCategoryAdapter childCategoryAdapter; @Override public UserCategoriesPresenter createPresenter() { return new UserCategoriesPresenter(); } @Nullable @Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_categories, container, false); mainCategories = getPresenter().getAllMainCategoryList(); return view; } @Override public void onDestroyView() { super.onDestroyView(); unbinder.unbind(); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); unbinder = ButterKnife.bind(this, view); EventBus.getDefault().register(this); } @NonNull @Override public UserCategoriesViewState createViewState() { return new UserCategoriesViewState(); } @Override public void onNewViewStateInstance() { } @Override public void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); }
}
fragment presenter class:
public class UserCategoriesPresenter extends MvpBasePresenter
{ public List<MainCategories> getAllMainCategoryList() { return SQLite.select().from(MainCategories.class).queryList(); }
}
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sockeqwe/mosby/issues/248, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjnrkcdhFMYOM_Pvp5gsMRR8eyAMWbvks5r_OyGgaJpZM4NrJIO .
@sockeqwe now how can i fix that? i don't understand how can i modify code
just move presenter interaction in onViewCreated()
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_categories, container, false);
return view;
}
@Override
public View onViewCreated(View view, Bundle bundle) {
super.onViewCreated(view, bundle);
// From now on, presenter is instantiated
mainCategories = getPresenter().getAllMainCategoryList();
}
when i trying to use this library to implementing mvp for fragments, i get
null
for getPresenter(),fragment presenter class: