public class RecyclerViewAdapter_Accueil extends RecyclerView.Adapter<RecyclerViewAdapter_Accueil.RestaurantViewHolder> {
private Double latitude;
private Double longitude;
private List<Restaurant> restaurantList;
private int descuento;
public RecyclerViewAdapter_Accueil( List<Restaurant> restaurant, Double latitude, Double longitude) {
this.restaurantList=restaurant;
this.latitude=latitude;
this.longitude=longitude;
}
@Override
public RecyclerViewAdapter_Accueil.RestaurantViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_restaurants, parent, false);
RestaurantViewHolder viewHolder = new RestaurantViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(final RestaurantViewHolder holder, final int position) {
final Restaurant mItems=this.restaurantList.get(position);
String nombreRestaurant=mItems.getName();
holder.tvTituloRestaurant.setText(nombreRestaurant);
descuento=mItems.tomarPromocion();
if (descuento>0){
holder.tvRestaurantPromocion.setVisibility(View.VISIBLE);
holder.tvRestaurantPromocion.setText(descuento+"%");
}
holder.test10(mItems);
// holder.test(restaurantList);
holder.test2(restaurantList);
holder.test3(restaurantList,latitude,longitude);
}
@Override
public int getItemCount() {
return (restaurantList == null) ? 0 : restaurantList.size();
}
public static class RestaurantViewHolder extends RecyclerView.ViewHolder {
// public ImageView imageView;
CustomFontTextView tvTituloRestaurant;
CustomFontTextView tvStateReservation;
CustomFontTextView tvKm;
CustomFontTextView tvRestaurantPromocion;
CustomFontTextView [] tvTag =new CustomFontTextView[6];
ImageView ivRestaurantList;
public RestaurantViewHolder(View itemView) {
super(itemView);
// imageView= (ImageView) itemView.findViewById(R.id.ivRestaurant);
tvKm= (CustomFontTextView) itemView.findViewById(R.id.tvKm);
tvTituloRestaurant = (CustomFontTextView)itemView.findViewById(R.id.tvTituloRestaurant);
tvStateReservation = (CustomFontTextView)itemView.findViewById(R.id.tvStateReservation);
ivRestaurantList = (ImageView) itemView.findViewById(R.id.ivRestaurantList);
tvRestaurantPromocion = (CustomFontTextView) itemView.findViewById(R.id.tvRestaurantPromocion);
tvTag[0] = (CustomFontTextView) itemView.findViewById(R.id.tvTag1);
tvTag[1] = (CustomFontTextView) itemView.findViewById(R.id.tvTag2);
tvTag[2] = (CustomFontTextView) itemView.findViewById(R.id.tvTag3);
tvTag[3] = (CustomFontTextView) itemView.findViewById(R.id.tvTag4);
tvTag[4] = (CustomFontTextView) itemView.findViewById(R.id.tvTag5);
tvTag[5] = (CustomFontTextView) itemView.findViewById(R.id.tvTag6);
}
public void test10(Restaurant restaurant){
if(restaurant.getTags()!=null) {
for (int x = 0; x < restaurant.getTags().size(); x++) {
String tag = restaurant.getTags().get(x);
tvTag[x].setVisibility(View.VISIBLE);
tvTag[x].setText(tag);
}
}
}
public void test3(List<Restaurant> restaurantList,Double latitude,Double longitude){
Location locationMain = new Location("");
locationMain.setLatitude(latitude);
locationMain.setLongitude(longitude);
Location locationRestaurant = new Location("");
locationRestaurant.setLatitude(restaurantList.get(getAdapterPosition()).getLatitude());
locationRestaurant.setLongitude(restaurantList.get(getAdapterPosition()).getLongitude());
float distanceInMeters = locationMain.distanceTo(locationRestaurant);
double distanceInKm= distanceInMeters/1000;
DecimalFormat df = new DecimalFormat("0.00");
tvKm.setText(String.valueOf(df.format(distanceInKm))+" Km");
}
public void test2(List<Restaurant> restaurantList){
switch (restaurantList.get(getAdapterPosition()).getStateOrder()){
case 0:
tvStateReservation.setText("Sur place/ À emporter");
break;
case 1:
tvStateReservation.setText("Sur place");
break;
case 2:
tvStateReservation.setText("À emporter");
break;
}
}
}
}
The problem is in the method called test10 Where I check the size of the list of tags from the object in the list of objects, to make textviews appear and show the corresponding tags
It works, but when I go through the whole list, I scroll downwards, when I return, tags that should not go in which already showed well appear, the correct tags appear and 1 tag that should not go.
For example, in the restaurant were the Italian and Pizza tags, when climbing Italian, pizza and traditional appears
Alado was a Japanese restaurant, before he said Japanese, now he says, Japanese and pizza.