我第一次显示孩子的布局时,我有一个recyclerview:
当我更改更大的布局时,我遇到同样的问题。
这是我的Adapter类(不考虑不同类型,这不是bug的来源,因为当我有一个ViewHolder类型时bug也存在)
private class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_ALERTS = 0 ;
private static final int TYPE_MOST_VIEWED = 1 ;
@Override
public RecyclerView.ViewHolder onCreateViewHolder (final ViewGroup parent, int viewType) {
if (viewType == TYPE_ALERTS){
View itemLayoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_item_alerts_home_home, null);
ViewHolderAlerts viewHolderAlerts = new ViewHolderAlerts(itemLayoutView);
itemLayoutView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
Intent intent = new Intent(activity, Activity_UpdateAlert.class);
intent.putExtra("alert", (AlertObj)listAllProducts.get(recyclerView.getChildAdapterPosition(v)));
startActivity(intent);
}
});
return viewHolderAlerts;
}else {
View itemLayoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_item_product_grid__list_products_by_category, null);
ViewHolder_Product_CatSearch viewHolder_product_catSearch = new ViewHolder_Product_CatSearch(itemLayoutView);
itemLayoutView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
Intent intent = new Intent(activity, Activity_ProductDetails.class);
intent.putExtra("product", (Product)listAllProducts.get(recyclerView.getChildAdapterPosition(v)));
startActivity(intent);
}
});
return viewHolder_product_catSearch ;
}
}
@Override
public void onBindViewHolder (RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == TYPE_ALERTS){
((ViewHolderAlerts)holder).textViewTitle.setText(((AlertObj)listAllProducts.get(position)).product.name);
((ViewHolderAlerts)holder).textViewPrice.setText(new DecimalFormat("###0.00")
.format(Double.valueOf(((AlertObj)listAllProducts.get(position)).product.price)) +
((AlertObj)listAllProducts.get(position)).product.currency);
Glide.with(activity.getApplicationContext())
.load(((AlertObj)listAllProducts.get(position)).product.imgUrl)
.error(R.drawable.picture_not_available)
.into(((ViewHolderAlerts) holder).imgView);
}else {
((ViewHolder_Product_CatSearch)holder).textViewName.setText(((ProductMostViews)listAllProducts.get(position)).name);
((ViewHolder_Product_CatSearch)holder).textViewPrice.setText(new DecimalFormat("###0.00")
.format(Double.valueOf(((ProductMostViews)listAllProducts.get(position)).price)) +
((ProductMostViews)listAllProducts.get(position)).currency);
Glide.with(activity.getApplicationContext())
.load(((ProductMostViews)listAllProducts.get(position)).imgUrl)
.error(R.drawable.picture_not_available)
.into(((ViewHolder_Product_CatSearch) holder).imageViewProduct);
}
}
@Override
public int getItemViewType (int position) {
return listAllProducts.get(position) instanceof AlertObj ? TYPE_ALERTS : TYPE_MOST_VIEWED ;
}
@Override
public long getItemId (int position) {
return listAllProducts.get(position) instanceof AlertObj ? TYPE_ALERTS : TYPE_MOST_VIEWED ;
}
@Override
public int getItemCount () {
return listAllProducts.size();
}
}
感谢&#39; S