ButterKnife: Zero Views After Resting Fragments on ViewPager

I am working with the latest version of Butterknife (8.2.1), and I have a problem: I use a ViewPager with 3 fragments, when the Fragment is recreated, all views become null! The first 2 fragments, no problem, but when I scroll to the third and return to the first, each view becomes zero. What could be the problem?

I added ButterKnife.setDebug(true); to get more information about the problem, and I get the following:

 D/ButterKnife: Looking up view binder for com.example.overview.MeetupOverviewFragment D/ButterKnife: HIT: Cached in view binder map. D/ButterKnife: Looking up view binder for com.example.attendees.MeetupAttendeesFragment D/ButterKnife: HIT: Cached in view binder map. D/ButterKnife: Looking up view binder for com.example.attendees.ControllerListAttendees$ItemViewHolder D/ButterKnife: HIT: Cached in view binder map. D/ButterKnife: Looking up view binder for com.example.attendees.ControllerListAttendees$ItemViewHolder D/ButterKnife: HIT: Cached in view binder map. D/ButterKnife: Looking up view binder for com.example.attendees.ControllerListAttendees$ItemViewHolder D/ButterKnife: HIT: Cached in view binder map. I/InjectionManager: dispatchCreateOptionsMenu :com.example.MeetupDetailActivity I/InjectionManager: dispatchPrepareOptionsMenu :com.example.MeetupDetailActivity 

For fragments (as the wiki says) I do this:

 public class MeetupDocumentsFragment extends Fragment { @BindView(R.id.list) CustomRecyclerView recyclerView; private Unbinder unbinder; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) { View v = inflater.inflate(R.layout.my_layout, container, false); unbinder = ButterKnife.bind(this, v); return v; } @Override public void onDestroyView() { super.onDestroyView(); unbinder.unbind(); } } 

For RecyclerViewAdapters, I use this code:

 public class ControllerListAttendees extends RecyclerView.Adapter<ControllerListAttendees.ItemViewHolder> public static class ItemViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.some_imageview) ImageView imageAvatar; @BindView(R.id.some_label1) TextView labelName; @BindView(R.id.some_label2) TextView labelSurname; @BindView(R.id.some_label3) TextView labelAge; public ItemViewHolder(View v) { super(v); ButterKnife.bind(this, v); } } } 

In the meantime, I could just set OffscreenLageit ViewPager to 2 to avoid rest, but ... I would rather do it right :)

Can anyone help me with this?

+8
android android-fragments butterknife
source share

No one has answered this question yet.

See related questions:

702
How to determine when a fragment becomes visible in ViewPager
572
ViewPager PagerAdapter does not update View
462
ViewPager and fragments - what is the right way to store fragment state?
447
IllegalStateException: Cannot complete this action after onSaveInstanceState using ViewPager
249
Replace fragment inside ViewPager
215
Extracting a fragment from ViewPager
23
Android: how to recreate the action bar when changing a fragment
4
Viewpager does not save images properly
3
Fragment inside ViewPager disappears when scrolling
0
Viewpager in fragment

All Articles