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?
android android-fragments butterknife
iroyo
source share