ButterKnife:ViewPager上Fragment娱乐后的空视图

时间:2016-07-18 13:16:57

标签: android android-fragments butterknife

我正在使用最新版本的Butterknife(8.2.1),我遇到了一个问题:我正在使用带有3个片段的ViewPager,当重新创建片段时,所有视图都变为空!前两个片段,没问题,但是当我滑到第三个并返回到第一个时,每个视图都变为空。 可能是什么问题?

我添加了ButterKnife.setDebug(true);以获取有关该问题的更多信息,我得到了这个:

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

对于碎片(正如维基所说)我正在这样做:

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();
    }

}

对于RecyclerViewAdapters我正在使用此代码:

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);
        }
    }

}

与此同时,我可以将ViewPager的 OffscreenPageLimit 设置为2,以避免娱乐,但......我宁愿以正确的方式去做:)

任何人都可以帮助我吗?

0 个答案:

没有答案