我正在butterknife
使用retrofit
. 当我通过网络调用连续加载片段时,我的片段在视图上以空指针崩溃。我已经onDestroyView()
在片段中实现了 unbind ...?
使用findviewbyid
. 我正在使用 MVP 。
Unbinder unbinder;
@BindView(R.id.swipe_refresh_layout)
SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.recycler_view_shop)
RecyclerView recyclerView;
@BindView(R.id.ll_content)
LinearLayout layoutContent;
@BindView(R.id.ll_no_data)
LinearLayout layoutNoData;
@BindView(R.id.tv_category_heading)
TextView categoryHeading;
private HomeActivity activity;
private ProgressDialog progressDialog;
DrListFragmentPresenter presenter;
public DrListFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_dr, container, false);
// bind view using butter knife
unbinder = ButterKnife.bind(this, rootView);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(getFragment().getActivity(),DividerItemDecoration.VERTICAL));
activity = (HomeActivity) getActivity();
presenter = new DrListFragmentPresenterImpl(this);
return rootView;
}
@Override
public Fragment getFragment() {
return this;
}
@Override
public void setCategoriesDetailsAdapter(CategoryWiseItemListingAdapter adapter) {
recyclerView.setAdapter(adapter);
}
@Override
public void onDestroyView() {
super.onDestroyView();
// unbind the view to free some memory
unbinder.unbind();
}
}