@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_CATEGORY) {
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_category, parent, false);
ListMainCategoryViewHolder listMainCategoryViewHolder = new ListMainCategoryViewHolder(mView);
return listMainCategoryViewHolder;
} else if (viewType == TYPE_ITEM) {
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_item, parent, false);
ListMainItemViewHolder listMainItemViewHolder = new ListMainItemViewHolder(mView);
return listMainItemViewHolder;
} else {
throw new RuntimeException("view holder not found");
}
}
Debugging I can see that it enters the first IF statement (if (viewType == TYPE_CATEGORY){...}
), it executes till ListMainCategoryViewHolder listMaingCategoryViewHolder = new..
, it doesn't execute the first return
and instead it goes suddenly to the statement return listMainItemViewHolder;
which is actually absurd to happens.
1st- Because viewType=0
, TYPE_CATEGORY=0
, TYPE_ITEM=1
. So it cannot enter the first IF
and then enter the second IF
without checking the condition
.
2nd- It doesnt execute a part of statement
inside the first IF
, especially the RETURN
. What is wrong?
I've currently uploaded a video on youtube that shows how it happens, so you can see with your eyes the problem here: https://youtu.be/9D_O2ulz0e8
Aucun commentaire:
Enregistrer un commentaire