-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurantsAdapter.java
More file actions
68 lines (50 loc) · 1.94 KB
/
Copy pathRestaurantsAdapter.java
File metadata and controls
68 lines (50 loc) · 1.94 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
package com.example.wagbaapplication;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class RestaurantsAdapter extends RecyclerView.Adapter<RestaurantsAdapter.RestaurantsViewHolder> {
private final LayoutInflater inflater;
ArrayList<RestaurantsModel> restaurantsModelsInternal;
ClickListener listener;
public RestaurantsAdapter(Context context, ArrayList<RestaurantsModel> restaurants, ClickListener listener) {
inflater = LayoutInflater.from(context);
restaurantsModelsInternal = restaurants;
this.listener = listener;
}
@NonNull
@Override
public RestaurantsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view =inflater.inflate(R.layout.rv_item_restaurant,parent,false);
return new RestaurantsViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull RestaurantsViewHolder holder, int position) {
holder.name.setText(restaurantsModelsInternal.get(position).getName());
holder.name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
listener.click(holder.getAdapterPosition());
}
});
}
@Override
public int getItemCount() {
return restaurantsModelsInternal.size();
}
public class RestaurantsViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public RestaurantsViewHolder(@NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.textViewRestaurant);
}
}
}