首页 > 解决方案 > 片段查看器没有附加适配器;跳过布局

问题描述

我尝试了很多解决方案,但没有一个解决方案对我有用。我正在从服务器获取数据并将其显示在回收视图中。数据显示正常,但在 logcat 中显示此错误

Access denied finding property "persist.vendor.log.tel_dbg"
E/RecyclerView: No adapter attached; skipping layout
E/RecyclerView: No adapter attached; skipping layout

有时当我一次又一次地刷新时,recyclerview 会变空。我正在使用由父片段内的 2 个片段组成的 viewpager。这个 recycleview 在嵌套的滚动视图中使用了一些时间数据不显示代码片段:

homebuyer_adapter_recycler=new homebuyer_adapter_recycle(getActivity(), items);
LinearLayoutManager home = new LinearLayoutManager(getActivity());                         
home.setOrientation(LinearLayoutManager.VERTICAL);                      
allitemsgrid.setLayoutManager(home);
allitemsgrid.setAdapter(r);

这里有更多关于

          @Override
         public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, 
          final int viewType) {
    View v = LayoutInflater.from(context).inflate(R.layout.items_view,parent, 
             false);
    RecyclerView.LayoutParams lp = new 
         RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
                 v.setLayoutParams(lp);
              ViewHolder viewHolder = new ViewHolder(v);

这是我的物品视图

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


android:orientation="vertical">
<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="3dp"
    app:cardCornerRadius="6dp"
    android:layout_marginBottom="3dp"
    app:cardBackgroundColor="@color/white">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical">
    <RelativeLayout

        android:layout_width="match_parent"
        android:layout_height="150dp">
        <com.makeramen.roundedimageview.RoundedImageView
            android:layout_width="match_parent"
            android:layout_height="150dp"
            app:riv_corner_radius="6dp"
            android:id="@+id/image_items"
            android:scaleType="fitXY"
            />
        <com.makeramen.roundedimageview.RoundedImageView
            android:layout_width="match_parent"
            android:layout_height="150dp"
            app:riv_corner_radius="6dp"
            android:background="@drawable/blackshade"
            android:scaleType="fitXY"/>
        <TextView
            android:id="@+id/items_all"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:padding="@dimen/_5sdp"
            android:textColor="@color/white"


            android:fontFamily="sans-serif-smallcaps"
            android:paddingLeft="20dp"

            android:text="Message" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"

            android:text="Timing"
            android:padding="@dimen/_5sdp"

            android:textColor="@color/white"

            android:layout_alignParentBottom="true"
            android:fontFamily="@font/mylight"
            android:layout_alignParentRight="true"

            android:textSize="10dp"
            android:id="@+id/shoptimming"/>



    </RelativeLayout>


    <TextView
        android:id="@+id/name_item"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"

        android:alpha="0.6"
        android:fontFamily="@font/arimo_bold"
        android:paddingLeft="20dp"
        android:text="Name"
        android:textColor="@color/black"
        android:textSize="17dp"




        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/minumum_order"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_marginBottom="5dp"
            android:layout_weight="1"

            android:drawablePadding="10dp"

            android:fontFamily="sans-serif"
            android:paddingLeft="20dp"
            android:text="Minimum " />

        <TextView
            android:id="@+id/price_item"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"


            android:fontFamily="sans-serif"
            android:gravity="left"
            android:paddingLeft="20dp"
            android:text="charges"


            />






    </LinearLayout>





     </LinearLayout>
   </androidx.cardview.widget.CardView>


      </LinearLayout>

这是我的适配器类

public class homebuyer_adapter_recycle extends RecyclerView.Adapter<homebuyer_adapter_recycle.ViewHolder> {
private ArrayList<seller_information> listData;

private LayoutInflater layoutInflater;
int lastpostition=-1;
Context context;

public homebuyer_adapter_recycle(Context aContext, ArrayList<seller_information> listData) {
    this.listData = listData;
    layoutInflater = LayoutInflater.from(aContext);
    context=aContext;
}

@NonNull
@Override
        public ViewHolder onCreateViewHolder
        (@NonNull ViewGroup parent, final 
       int viewType) {
    View v = LayoutInflater.from(parent.getContext()).
    inflate(R.layout.items_view,parent, false);
           
    ViewHolder viewHolder = new ViewHolder(v);
    Log.i("inadapter","calling time");
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            phone_number_shop = listData.get(viewType).getPhonenumber();
            homebuyer.Delivery_charges_shop = 
       listData.get(viewType).getDiliveryfee();
            homebuyer.Shop_name = listData.get(viewType).getShopname();
            homebuyer.minimum_order = listData.get(viewType).getMinorder();
            //profession=items.get(i).getName();


            // Toast.makeText(getActivity(),phn,Toast.LENGTH_SHORT).show();
            all_and_cetegory_items items = new all_and_cetegory_items();
            Bundle b = new Bundle();
            b.putString("phone",homebuyer.phone_number_shop);

            items.setArguments(b);


            FragmentTransaction fragmentTransaction = 
  
    ((AppCompatActivity)context).getSupportFragmentManager()
      .beginTransaction();
            fragmentTransaction.replace(R.id.nav_host_fragment, items);
            fragmentTransaction.addToBackStack(null).commit();

        }
    });
    return viewHolder;
}

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

    holder.name.setText(listData.get(position).getShopname());
    // 
      Picasso.with(context).load(listData.get(position)
    .getShopimage()).into(holder.shopimage);

 Glide.with(context).load(listData.get(position).getShopimage())
  .into(holder.shopimage);
    holder.dilivery.setText("Rs "+listData.get(position).getDiliveryfee()+" 
  Delivery fee");
    holder.minorder.setText("Rs "+listData.get(position).getMinorder()+" minimum");
    holder.items.setText(listData.get(position).getShopmessage());
    holder.time.setText("Service Available  
   "+listData.get(position).getStartingtime()+"  to  
 "+listData.get(position).getEndingtime());


    Log.i("inadapter","calling time"+listData.get(position).getShopname());

}


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

public  class ViewHolder extends RecyclerView.ViewHolder {
    TextView name;
    TextView dilivery;
    TextView items;
    TextView minorder;
    TextView time;
    ImageView shopimage;

    public ViewHolder(@NonNull View v) {
        super(v);
        name = (TextView) v.findViewById(R.id.name_item);
      dilivery = (TextView) v.findViewById(R.id.price_item);

       minorder = (TextView) v.findViewById(R.id.minumum_order);
        items=(TextView)v.findViewById(R.id.items_all);
        time=(TextView)v.findViewById(R.id.shoptimming);
       shopimage=(ImageView) v.findViewById(R.id.image_items);

    }
}

}

标签: javaandroid-studioandroid-recyclerview

解决方案


错误地说,RecylerView 的适配器未附加。因此,尝试使用以下方法将适配器添加到布局中:

recyclerView.setAdapter(categoryAdapter);


推荐阅读