android中的RecyclerView没有显示列表项

时间:2017-02-13 12:32:58

标签: android android-layout android-recyclerview

我在android中实现recyler视图.arraylist显示正确的列表大小,当我调试代码时,适配器也得到设置。但是列表项不显示可能是由于createViewHolder和bindviewHolder.Below是代码RecyclerViewAdapter

MyAdapter.java

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    public Context c;
    View img_View;
    File file;
    public ArrayList<Bean> arr= new ArrayList<>();
    LayoutInflater inflator;

    public MyAdapter(Context applicationContext, ArrayList<Bean> arr) {
        this.c = applicationContext;
        this.arr= arr;
        inflator =  LayoutInflater.from(c.getApplicationContext());
    }

    @Override
    public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        img_View =inflator.inflate(R.layout.list_row, parent, false);
        return new MyViewHolder(img_View);
    }

    @Override
    public void onBindViewHolder(MyAdapter.MyViewHolder holder, int position) {
                holder.title.setText(arr.get(position).gettitle());

    }

    @Override
    public int getItemCount() {
        return arr.size();
    }
    public class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView desc, title;


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

            title = (TextView) view.findViewById(R.id.tv_title);

        }
    }

1 个答案:

答案 0 :(得分:2)

    img_View = LayoutInflater.from(context).inflate(R.layout.list_row, parent, false);
      return new MyViewHolder(img_View);