我有一个错误“ E / RecyclerView:未连接适配器:正在跳过布局”

时间:2019-02-09 06:12:46

标签: android android-studio android-recyclerview

当我访问RecyclerView所在的活动时,我的应用程序关闭,它告诉我问题出在适配器上,但是这是新问题,事实是我不知道解决方案是什么。我已经在寻找具有相同问题的其他答案,但仍然无法解决问题

public class RecyclerViewAdapterCategoria extends RecyclerView.Adapter<RecyclerViewAdapterCategoria.MyViewHolder> {

    private Context mContext;
    private List<Categoria> mData;
    private RequestOptions option;

    public RecyclerViewAdapterCategoria(Context mContext, List<Categoria> mData) {
        this.mContext = mContext;
        this.mData = mData;

        //Request option for Glide

        option = new RequestOptions().centerCrop().placeholder(R.drawable.loading_shape).error(R.drawable.loading_shape);

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {

        View view;
        LayoutInflater inflater = LayoutInflater.from(mContext);
        view = inflater.inflate(R.layout.categoria_row_item, parent, false);
        final MyViewHolder viewHolder = new MyViewHolder(view);


        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        holder.tv_id.setText(mData.get(position).getId_categoria());
        holder.tv_nombre.setText(mData.get(position).getNombre());

        //Load image from Internet

        Glide.with(mContext).load(mData.get(position).getImagen_url()).apply(option).into(holder.iv_imagen);

    }

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

    public static class MyViewHolder extends RecyclerView.ViewHolder{

        TextView tv_id;
        TextView tv_nombre;
        ImageView iv_imagen;
        LinearLayout view_container;

        public MyViewHolder(View itemView){
            super(itemView);


            view_container = itemView.findViewById(R.id.container);
            tv_id = itemView.findViewById(R.id.categoria_id);
            tv_nombre = itemView.findViewById(R.id.categoria_nombre);
            iv_imagen = itemView.findViewById(R.id.categoria_imagen);

        }

    }

}

2 个答案:

答案 0 :(得分:1)

由于语言原因,我无法理解您的问题。但是您的标题是E/RecyclerView: No adapter attached; skipping layout。因此,我认为您错过了在yourRecyclerViewActivity类中声明适配器的机会。 基本而言,您必须添加

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(this,yourList);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setAdapter(myAdapter );

进入您的recyclerViewActivity班。

答案 1 :(得分:0)

@vimukthi是正确的,您可能在进行绑定并调用recyclerView的类上缺少此代码recyclerView.setAdapter(myAdapter);