Java 循环视图适配器未加载项

Java 循环视图适配器未加载项,java,android,android-recyclerview,Java,Android,Android Recyclerview,我是android新手,我用它的适配器创建了recycler视图,但它不工作。检查以下代码 我试图调试此活动,但没有错误。而且在OtherOfferingAdapter中,程序在getItemCount()之后不再执行 文件OtherOfferingAdapter.java public class OtherOfferingAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private Con

我是android新手,我用它的适配器创建了recycler视图,但它不工作。检查以下代码

我试图调试此活动,但没有错误。而且在
OtherOfferingAdapter
中,程序在
getItemCount()之后不再执行

文件OtherOfferingAdapter.java

public class OtherOfferingAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private LayoutInflater inflater;
    List<OtherOfferingData> data = Collections.emptyList();
    OtherOfferingData current;
    int currentPos=0;



    //Create constructor to innitilize context and data sent from MainActivity

    public OtherOfferingAdapter(Context context,List<OtherOfferingData> data){
        this.context=context;
        inflater = LayoutInflater.from(context);
        this.data=data;
    }

    //Inflate the layout when viewholder created
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        View view = inflater.inflate(R.layout.container_offerings, parent, false);
        MyHolder holder = new MyHolder(view);
        return holder;
    }

    //Bind Data
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position){
        MyHolder myHolder = (MyHolder) holder;
        current = data.get(position);
        myHolder.inputOfferingName.setText(current.offeringname);
        myHolder.inputOfferingPrice.setText(current.price);
        myHolder.inputOfferingRating.setRating(Float.parseFloat(current.rating));

        Picasso.with(context).load(current.imageUrl).into(myHolder.inputOfferingImage);
        if(current.dietType.equals("1")){
            myHolder.inputDietType.setBackgroundResource(R.drawable.veg);
        }else{
            myHolder.inputDietType.setBackgroundResource(R.drawable.nonveg);
        }
    }

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

    class MyHolder extends RecyclerView.ViewHolder{

        ImageView inputOfferingImage, inputDietType;
        TextView inputOfferingPrice, inputOfferingName;
        RatingBar inputOfferingRating;

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

            inputOfferingImage = (ImageView) itemView.findViewById(R.id.otherimage);
            inputDietType = (ImageView) itemView.findViewById(R.id.otherdietType);
            inputOfferingPrice = (TextView) itemView.findViewById(R.id.otherprice);
            inputOfferingName = (TextView) itemView.findViewById(R.id.otherofferingnanme);
            inputOfferingRating = (RatingBar) itemView.findViewById(R.id.otherrating);

        }
    }
}
我是这样调用适配器的

recyclerView = (RecyclerView) findViewById(R.id.recycle_view);
                        offeringAdapter = new OtherOfferingAdapter(ProductDescriptionActivity.this, data);
                        recyclerView.setAdapter(offeringAdapter);
                        recyclerView.setLayoutManager(new LinearLayoutManager(ProductDescriptionActivity.this));
container\u offices.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:layout_marginBottom="30dp"
    android:background="@color/lightGray"
    android:paddingLeft="15dp"
    android:paddingRight="15dp">

活动页面

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:design="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
                        android:id="@+id/recycle_view"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        xmlns:android="http://schemas.android.com/apk/res/android"
                        android:background="@color/lightGray"
                        android:layout_marginBottom="90dp"/>


谢谢

相对布局中回收器视图的大小为0dp请尝试更改

 android:layout_width="0dp"
 android:layout_height="0dp"
两者都要匹配父项

 android:layout_width="match_parent"
 android:layout_height="match_parent"
您的recycler视图及其适配器似乎很好。但它们不会出现在屏幕上,因为它们的维度为0dp

 android:layout_width="match_parent"
 android:layout_height="match_parent"