RecyclerView不起作用

时间:2016-02-19 14:13:37

标签: android android-recyclerview

我在RecyclerView中创建了RecyclerView,但由于某些原因我的图片没有显示在内部。求救!

public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    switch (holder.getItemViewType()) {

        case TYPE_SUBSKRIBE_LIKE_AS:

            SubscribeLikeAsHolder subscribeLikeAs = (SubscribeLikeAsHolder) holder;

            subscribeLikeAs.recyclerViewImagines.setLayoutManager(new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false));

            subscribeLikeAs.recyclerViewImagines.setAdapter(imageRecyclerViewAdapter);

            break;
    }
}


public class ImageRecyclerViewAdapter extends RecyclerView.Adapter<ImageRecyclerViewAdapter.ImagesViewHolder>{

private Context ctx;
private LayoutInflater lInflater;
private ArrayList<ItemsImage> images;


public  void InForEntries (Context context, ArrayList<ItemsImage>  items) {

    ctx =  context;
    images = items;
    lInflater = (LayoutInflater) ctx
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}

public static class ImagesViewHolder extends RecyclerView.ViewHolder {

    ImageView image;

    ImagesViewHolder(View itemView) {
        super(itemView);
        image = (ImageView) itemView.findViewById(R.id.imageViewSmall);
    }
}

@Override
public ImagesViewHolder onCreateViewHolder(ViewGroup viewGroup, int typeView) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_for_images, viewGroup, false);
    return new ImagesViewHolder(view);
}

@Override
public void onBindViewHolder(ImageRecyclerViewAdapter.ImagesViewHolder holder, int position) {

   // holder.image.setBackground(images.get(position).getDrawable());

    holder.image.setBackground(ctx.getResources().getDrawable(R.drawable.image_1));

}

@Override
public int getItemCount() {
    return images.size();
}



@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}

}

1 个答案:

答案 0 :(得分:0)

我犯的一个常见错误是忘记将LinearLayoutManager设置为RecyclerView。

    private LinearLayoutManager mLayoutManager;
    RecyclerView mRecyclerView;

    mLinearLayoutManager = new LinearLayoutManager(context);
    mLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);