onCreateViewHolder不叫RecyclerView

时间:2017-02-28 15:10:44

标签: android android-recyclerview cardview

我正在使用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();
    }}

Recyclerview

 RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(mLayoutManager);

XML

<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>

正在调用DishesAdapter构造函数。我得到了follower1 log以及项目列表。

0 个答案:

没有答案