-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoodListAdapter.java
More file actions
86 lines (74 loc) · 3.23 KB
/
Copy pathFoodListAdapter.java
File metadata and controls
86 lines (74 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.example.foodiemenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
public class FoodListAdapter extends RecyclerView.Adapter<FoodListAdapter.ViewHolder> {
ArrayList<FoodList> listDomain;
public FoodListAdapter(ArrayList<FoodList> listDomain) {
this.listDomain = listDomain;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_holder, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.ListName.setText(listDomain.get(position).getTitle());
String picUrl = "";
switch (position) {
case 0:
picUrl = "a";
holder.mainLayout.setBackground(ContextCompat.getDrawable(holder.itemView.getContext(), R.drawable.brawn_button_a));
break;
case 1:
picUrl = "b";
holder.mainLayout.setBackground(ContextCompat.getDrawable(holder.itemView.getContext(), R.drawable.brawn_button_b));
break;
case 2:
picUrl = "c";
holder.mainLayout.setBackground(ContextCompat.getDrawable(holder.itemView.getContext(), R.drawable.brawn_button_c));
break;
case 3:
picUrl = "d";
holder.mainLayout.setBackground(ContextCompat.getDrawable(holder.itemView.getContext(), R.drawable.brawn_button_d));
break;
case 4:
picUrl = "e";
holder.mainLayout.setBackground(ContextCompat.getDrawable(holder.itemView.getContext(), R.drawable.brawn_button_e));
break;
case 5:
picUrl = "f";
holder.mainLayout.setBackground(ContextCompat.getDrawable(holder.itemView.getContext(), R.drawable.brawn_button_f));
break;
}
int drawableResourceId = holder.itemView.getContext().getResources().getIdentifier(picUrl, "drawable", holder.itemView.getContext().getPackageName());
Glide.with(holder.itemView.getContext())
.load(drawableResourceId)
.into(holder.ListPic);
}
@Override
public int getItemCount() {
return listDomain.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView ListName;
ImageView ListPic;
ConstraintLayout mainLayout;
public ViewHolder(@NonNull View itemView) {
super(itemView);
ListName = itemView.findViewById(R.id.cat_name_1);
ListPic = itemView.findViewById(R.id.burgers);
mainLayout = itemView.findViewById(R.id.main_layout);
}
}
}