public class VisitorAdapterShop extends RecyclerView.Adapter<VisitorAdapterShop.VisitorHolderShop> {
private Context context;
public ArrayList<VisitorShopHelper> visShopsList;
public VisitorAdapterShop(Context context, ArrayList<VisitorShopHelper> visShopsList) {
this.context = context;
this.visShopsList = visShopsList;
}
@NonNull
@Override
public VisitorHolderShop onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//inflate layout
View view = LayoutInflater.from(context).inflate(R.layout.row_visitor_shop,parent,false);
return new VisitorHolderShop(view);
}
@Override
public void onBindViewHolder(@NonNull VisitorHolderShop holder, int position) {
//get data
VisitorShopHelper visitorShopHelper = visShopsList.get(position);
String vis_seller_full_name = visitorShopHelper.getVFullname();
String vis_seller_email = visitorShopHelper.getVEmail();
String vis_seller_contact = visitorShopHelper.getVContact();
String vis_seller_address = visitorShopHelper.getVAddress();
String vis_seller_image = visitorShopHelper.getVimage();
String uid = visitorShopHelper.getVuid();
//set data
holder.tv_vis_sellerName.setText(vis_seller_full_name);
holder.tv_vis_sellerEmail.setText(vis_seller_email);
holder.tv_vis_sellerContact.setText(vis_seller_contact);
holder.tv_vis_sellerAddress.setText(vis_seller_address);
try {
Picasso.get().load(vis_seller_image).placeholder(R.drawable.ic_shop_black_24dp).into(holder.visShopImage);
}
catch (Exception e) {
holder.visShopImage.setImageResource(R.drawable.ic_shop_black_24dp);
}
}
@Override
public int getItemCount() {
return visShopsList.size();
}
//view holder
class VisitorHolderShop extends RecyclerView.ViewHolder {
private ImageView visShopImage;
private TextView tv_vis_sellerName, tv_vis_sellerEmail, tv_vis_sellerContact ,tv_vis_sellerAddress;
public VisitorHolderShop(@NonNull View itemView) {
super(itemView);
visShopImage = itemView.findViewById(R.id.tv_vis_shopImage);
tv_vis_sellerName = itemView.findViewById(R.id.tv_vis_sellerName);
tv_vis_sellerEmail = itemView.findViewById(R.id.tv_vis_sellerEmail);
tv_vis_sellerContact = itemView.findViewById(R.id.tv_vis_sellerContact);
tv_vis_sellerAddress = itemView.findViewById(R.id.tv_vis_sellerAddress);
}
}
}
public class VisitorHomepage extends AppCompatActivity {
ArrayList <VisitorShopHelper> visShopList;
VisitorAdapterShop visitorAdapterShop;
RecyclerView visShopRecycler;
FirebaseAuth fAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_visitor_homepage);
visShopRecycler = findViewById(R.id.visShopsRecycler);
fAuth = FirebaseAuth.getInstance();
loadShop();
}
private void loadShop () {
visShopList = new ArrayList<>();
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("users");
databaseReference.orderByChild("Type").equalTo("Seller").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//clear list at start
visShopList.clear();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
VisitorShopHelper visitorShopHelper = ds.getValue(VisitorShopHelper.class);
visShopList.add(visitorShopHelper);
}
//setup adapter
visitorAdapterShop = new VisitorAdapterShop(VisitorHomepage.this,visShopList);
//set adapter to recycler view
visShopRecycler.setAdapter(visitorAdapterShop);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
First paragraph of code is for the adapter whereas the second paragraph of code is for the activity. When I run the code, I get the error message of adapter not attached, skipping layout. The codes shown here are also used in other parts of my application and it worked. Any help regarding this issue would be highly appreciated.