简体   繁体   中英

Fragment viewpager No adapter attached; skipping layout

I tried a lot of solutions but no solution has worked for me. I am getting data from the server and showing it inside a recycleview. The data shows fine but shows this error in the logcat

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

sometimes when I refresh again and again the recyclerview becomes empty. I am using viewpager consisting of 2 fragments inside a parent fragment. this recycleview is using in a nested scrollview some time data not showing Code snippet:

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

Here is more about

          @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);

HERE IS MY item view

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

Here is my adapter class

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

    }
}

}

In error it is saying that the Adapter for RecylerView is not attached. So, try to add adapter to the layout using:

recyclerView.setAdapter(categoryAdapter);

I am assuming homebuyer_adapter_recycler is your adapter. According to that, you haven't really set your adapter as the logcat is specifying.

Add the below code instead of allitemsgrid.setAdapter(r);

allitemsgrid.setAdapter(homebuyer_adapter_recycler);

If my assumption or suggestion is wrong, it is okay. It is probably because your question is not very clear and does not provide the necessary details. Please provide more details such as the adapter class code and what is allitemsgrid , homebuyer_adapter_recycler and r .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM