Unbind Butterknife-injected views in fragment's onDestroyView()

This commit is contained in:
tonymanou
2017-01-12 01:46:07 +01:00
committed by topjohnwu
parent e81bc4f044
commit a718f9bbfd
6 changed files with 54 additions and 7 deletions

View File

@@ -26,6 +26,7 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
public class ModulesFragment extends Fragment implements CallbackHandler.EventListener {
@@ -33,6 +34,7 @@ public class ModulesFragment extends Fragment implements CallbackHandler.EventLi
private static final int FETCH_ZIP_CODE = 2;
private Unbinder unbinder;
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.recyclerView) RecyclerView recyclerView;
@BindView(R.id.empty_rv) TextView emptyTv;
@@ -44,7 +46,7 @@ public class ModulesFragment extends Fragment implements CallbackHandler.EventLi
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.modules_fragment, container, false);
ButterKnife.bind(this, view);
unbinder = ButterKnife.bind(this, view);
fabio.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
@@ -105,6 +107,12 @@ public class ModulesFragment extends Fragment implements CallbackHandler.EventLi
super.onStop();
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
private void updateUI() {
ModuleHelper.getModuleList(listModules);
if (listModules.size() == 0) {