Adapter isn't showing the menu properly just shows a blank screen my issue before was that i didn't initilize the code but found a way to initilize it finally. now the code runs but i'm presented with a black screen that is supposed to show the menu
any tips is greatly appreciated
The culprit
public class FoodListAdapter extends RecyclerView.Adapter<FoodListAdapter.MyViewHolder> {
private List<Foods> foodList;
private FoodListClickListener clickListener;
public FoodListAdapter(List<Foods> foodList, FoodListClickListener clickListener) {
this.foodList = foodList;
this.clickListener = clickListener;
}
public void updateData(List<Foods> foodList) {
this.foodList = foodList;
notifyDataSetChanged();
}
@NonNull
@Override
public FoodListAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_recycler_row, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull FoodListAdapter.MyViewHolder holder, int position) {
holder.menuName.setText(foodList.get(position).getName());
holder.menuPrice.setText("Price: $"+foodList.get(position).getPrice());
holder.addToCartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Foods food = foodList.get(position);
food.setTotalInCart(1);
clickListener.onAddToCartClick(food);
holder.addMoreLayout.setVisibility(View.VISIBLE);
holder.addToCartButton.setVisibility(View.GONE);
holder.tvCount.setText(food.getTotalInCart()+"");
}
});
holder.imageMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Foods food = foodList.get(position);
int total = food.getTotalInCart();
total--;
if(total > 0 ) {
food.setTotalInCart(total);
clickListener.onUpdateCartClick(food);
holder.tvCount.setText(total +"");
} else {
holder.addMoreLayout.setVisibility(View.GONE);
holder.addToCartButton.setVisibility(View.VISIBLE);
food.setTotalInCart(total);
clickListener.onRemoveFromCartClick(food);
}
}
});
holder.imageAddOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Foods food = foodList.get(position);
int total = food.getTotalInCart();
total++;
if(total <= 10 ) {
food.setTotalInCart(total);
clickListener.onUpdateCartClick(food);
holder.tvCount.setText(total +"");
}
}
});
Glide.with(holder.thumbImage)
.load(foodList.get(position).getUrl())
.into(holder.thumbImage);
}
@Override
public int getItemCount() {
List<Foods> foodList =new ArrayList<>();
return foodList.size();
}
static class MyViewHolder extends RecyclerView.ViewHolder {
TextView menuName;
TextView menuPrice;
TextView addToCartButton;
ImageView thumbImage;
ImageView imageMinus;
ImageView imageAddOne;
TextView tvCount;
LinearLayout addMoreLayout;
public MyViewHolder(View view) {
super(view);
menuName = view.findViewById(R.id.menuName1);
menuPrice = view.findViewById(R.id.menuPrice1);
addToCartButton = view.findViewById(R.id.addToCartButton1);
thumbImage = view.findViewById(R.id.thumbImage1);
imageMinus = view.findViewById(R.id.imageMinus1);
imageAddOne = view.findViewById(R.id.imageAddOne1);
tvCount = view.findViewById(R.id.tvCount1);
addMoreLayout = view.findViewById(R.id.addMoreLayout1);
}
}
public interface FoodListClickListener {
void onAddToCartClick(Foods food);
void onUpdateCartClick(Foods food);
void onRemoveFromCartClick(Foods food);
}
}
food model
public class Foods implements Parcelable{
private String name;
private float price;
private String url;
private int totalInCart;
public int getTotalInCart() { return totalInCart; }
public void setTotalInCart(int totalInCart) {
this.totalInCart = totalInCart;
}
protected Foods(Parcel in) {
name = in.readString();
price = in.readFloat();
url = in.readString();
totalInCart = in.readInt();
}
public static final Creator<Foods> CREATOR = new Creator<Foods>() {
@Override
public Foods createFromParcel(Parcel in) { return new Foods(in);
}
@Override
public Foods[] newArray(int size) { return new Foods[size]; }
};
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeFloat(price);
dest.writeString(url);
dest.writeInt(totalInCart);
}
}
json just in case
"menus":{
"Drinks": [
{
"Fresh Fruit Blends": ["Strawberry", "Strawberry Banana","Banana Smoothie","Mango","Papaya","Honeydew","Pineapple", "Avacado",
"Cantaloupe","Strawberry Lime","Fruit Tea","Mangonada"],
"price": 10.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/freshfruit.png?alt=media&token=13915c20-0d40-4542-a74e-20c791b085c2"
},
{
"100% Natural Juices": ["Orange Juice", "Watermelon", "Carrot", "Carrot Orange","Fresh Limeade","Nuoc Mat(Artichoke Tea"],
"price": 10.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/nmat100%25naturaljuice.png?alt=media&token=f264240d-1764-480e-8155-b4948b28c36f"
},
{
"Sea Foam": ["Matcha", "Earl Grey", "Jasmine", "Oolong","Thai Tea","Thai Green", "Black Coffee"],
"price": 10.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/seafoam.png?alt=media&token=d0175366-3310-4569-bbde-5aa30abcf533"
},
{
"Cream Tea": ["Matcha", "Cream Tea","Jasmine", "Thai Tea","Thai Green Tea", "Oolong Cream","Brown Sugar Milk","Taro Cream","Almond Cream", "Caramel Cream", "Chocolate Cream", "Coconut Cream",
"Honeydew", "Hazelnut", "Oreo Cream Tea", "Peppermint Cream Tea", "Vanilla Cream"],
"price": 10.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/bsmCreamtea.png?alt=media&token=da1ab8df-4e49-4c02-9080-e1dbb7d5c310"
},
{
"Flavored Tea": ["Jasmine Green Tea", "Passion Fruit", "Strawberry", "Mango","Peppermint", "Lime","Honey","Dried Plum",
"Green Apple","Peach","Lychee","Winter Melon","Pomegranate"],
"price": 10.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/sbgtea.png?alt=media&token=b74b21cc-8f77-47f1-aeb9-f3ecf744de54"
},
{
"Smoothie": ["Oreo Cookies & Cream","Taro","Coconut","Pina Colada","Blueberry w/ Ice-Cream","Almond","Red Bean",
"Chocolate","Frozen Matcha Green Tea","Orange Dreamsicle","Vanilla"],
"price": 10.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/tarosmoothie.png?alt=media&token=7fb66ea0-560a-4196-a152-dd09b1229a8c"
},
{
"Slurpy": ["Kiwi","Blueberry","Cherry","Grape","Green Apple", "Lychee","Passion Fruit","Peach"],
"price": 10.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/mangoslurpy.png?alt=media&token=07191718-3737-47e1-b2dd-26775fb61fc1"
},
{"Coffee": ["Ice-Cream","Frozen Vanilla Cappuccino","Frozen Mocha","Coffee Cream Tea","Cafe Sua Da","Caramel","Hazelnut","Vanilla","Peppermint","Hot Cocoa"],
"price": 10.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/FVFCOFFEE.png?alt=media&token=3c6f2b6b-3536-490a-838b-1fe027398d54"
}
],
"Foods" : [
{
"name": "Popcorn Chicken",
"price": 5.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/PopcornCkn.png?alt=media&token=a4112144-2e52-4237-b4a7-781bf0c676dc"
},
{
"name": "Sweet Potato Fries",
"price": 5.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/SweetPotato.png?alt=media&token=38e45dfc-e886-4f85-aa3e-d36bc051f6e1"
},
{
"name": "Egg Rolls",
"price": 5.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/Eggrolls.png?alt=media&token=221167d6-13b1-48e0-8527-12ee686ba452"
},
{
"name": "Calamari",
"price": 5.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/Calamari.png?alt=media&token=004a3bbb-48e9-4392-88ae-2760310ebb00"
},
{
"name": "Fried Squid Balls",
"price": 5.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/Squid.png?alt=media&token=634a516f-2d7e-4983-8afb-4c0073ae04e1"
},
{
"name": "Crinkle Cut Fries",
"price": 5.00,
"url": "https://firebasestorage.googleapis.com/v0/b/kims-tea-house.appspot.com/o/CrinkleFries.png?alt=media&token=b2a20607-1cfd-405d-96e9-ec92a0512576"
}
]
}
},