Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android onCreateViewHolder未调用RecyclerView_Android_Android Recyclerview_Cardview - Fatal编程技术网

Android onCreateViewHolder未调用RecyclerView

Android onCreateViewHolder未调用RecyclerView,android,android-recyclerview,cardview,Android,Android Recyclerview,Cardview,我使用的是Recyclerview,我的onCreateViewHolder和onBindViewHolder没有被调用。我正在获取数据,但它没有显示 我的适配器类 public class DishesAdapter extends RecyclerView.Adapter<DishesAdapter.MyViewHolder> { private Context mContext; List<List> DialogList = new ArrayL

我使用的是Recyclerview,我的onCreateViewHolder和onBindViewHolder没有被调用。我正在获取数据,但它没有显示

我的适配器类

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

    private Context mContext;
    List<List> DialogList = new ArrayList<List>();
        public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView dishnames;
        public RatingBar dishratings;
        public ImageView dishimages;
        private ImageLoader mLoader;

        public MyViewHolder(View view) {
            super(view);
            Log.d("follower2","hi");

            dishnames = (TextView)view.findViewById(R.id.dishname);
            dishimages = (ImageView)view.findViewById(R.id.dishimage);
            dishratings=(RatingBar)view.findViewById(R.id.dishrating);

        }
    }


    public DishesAdapter(Context mContext, List objects) {
        super();
        Log.d("follower1","hi");

        this.mContext = mContext;
        this.DialogList = objects;
        Log.d("follower1",objects.toString());

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext)
                .inflate(R.layout.recipe_list, parent, false);

        Log.d("follower","hi");

        return new MyViewHolder(itemView);
    }

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

        final int i=position;
        Log.d("follower","hi");

        List dialog = DialogList.get(i);
        Log.d("follower",dialog.toString());
        String dishid = dialog.get(0).toString();
        final String dishname = dialog.get(1).toString();
        //byte[] dishimage = Base64.decode(dialog.get(2).toString(), Base64.DEFAULT);
        String dishimage=dialog.get(2).toString();
        String rating=dialog.get(3).toString();

        holder.dishnames.setText(dishname);
        holder.dishratings.setRating(Float.parseFloat(rating));
        holder.mLoader.DisplayImage(dishimage.replaceAll(" ", "%20"),holder.dishimages);

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


行列表

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        card_view:cardUseCompatPadding="true"
        card_view:cardElevation="4dp"
        card_view:cardCornerRadius="3dp"
        android:id="@+id/cv">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            >
            <ImageView
                android:id="@+id/dishimage"
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:layout_marginRight="6dip"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                android:layout_margin="10dp"
                android:src="@drawable/portraitlanding"
                />


            <TextView
                android:id="@+id/dishname"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="40dp"
                android:layout_toRightOf="@+id/dishimage"
                android:textColor="#000000"
                android:textSize="20dp"
                android:layout_gravity="center"
                android:text="Andrew" />

            <RatingBar
                android:id="@+id/dishrating"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                style="?android:attr/ratingBarStyleSmall"
                android:isIndicator="true"
                android:numStars="5"
                android:stepSize="0.1"
                android:layout_marginTop="10dp"
                android:layout_gravity="center"
                android:layout_below="@+id/dishname"
                android:layout_toRightOf="@+id/dishimage"
                />


        </RelativeLayout>


    </android.support.v7.widget.CardView>
</LinearLayout>


正在调用DisheAdapter构造函数。我正在获取以下日志以及项目列表。

我们需要创建和设置RecyclerView的代码。是否向DialogList添加任何项目?同时显示
xml
。是DialogList显示适配器类中的所有项目。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="mealplanner.com.main.mealplanner.MainActivity"
    >
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:scrollbars="vertical" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        card_view:cardUseCompatPadding="true"
        card_view:cardElevation="4dp"
        card_view:cardCornerRadius="3dp"
        android:id="@+id/cv">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            >
            <ImageView
                android:id="@+id/dishimage"
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:layout_marginRight="6dip"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                android:layout_margin="10dp"
                android:src="@drawable/portraitlanding"
                />


            <TextView
                android:id="@+id/dishname"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="40dp"
                android:layout_toRightOf="@+id/dishimage"
                android:textColor="#000000"
                android:textSize="20dp"
                android:layout_gravity="center"
                android:text="Andrew" />

            <RatingBar
                android:id="@+id/dishrating"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                style="?android:attr/ratingBarStyleSmall"
                android:isIndicator="true"
                android:numStars="5"
                android:stepSize="0.1"
                android:layout_marginTop="10dp"
                android:layout_gravity="center"
                android:layout_below="@+id/dishname"
                android:layout_toRightOf="@+id/dishimage"
                />


        </RelativeLayout>


    </android.support.v7.widget.CardView>
</LinearLayout>