public class RecyclerViewAdapter_Restaurant extends RecyclerView.Adapter<RecyclerViewAdapter_Restaurant.mealViewHolder> {
private List<Meal> mealList;
private LayoutInflater mInflater;
private Context mContext;
private int cantidadComida = 0;
public RecyclerViewAdapter_Restaurant(Context context, List<Meal> mealList) {
this.mContext = context;
this.mInflater = LayoutInflater.from(context);
this.mealList = mealList;
}
@Override
public mealViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.row_meals_menu, parent, false);
mealViewHolder viewHolder = new mealViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(final mealViewHolder holder, final int position) {
holder.tvMealTitulo.setText(mealList.get(position).getName());
holder.tvMealPrecio.setText(String.valueOf(mealList.get(position).getPrice()));
holder.tvMealDescripcion.setText(mealList.get(position).getDescription());
holder.botonMasComida.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.tvCantidadComida.setText("" + (cantidadComida = cantidadComida + 1));
//RestaurantDetalle.agregarComida(mealList.get(position).getName() + "," + mealList.get(position).getPrice());
}
});
holder.botonMenosComida.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cantidadComida>0) {
holder.tvCantidadComida.setText("" +(cantidadComida = cantidadComida - 1));
}
}
});
}
@Override
public int getItemCount() {
return (mealList == null) ? 0 : mealList.size();
}
public static class mealViewHolder extends RecyclerView.ViewHolder {
CustomFontTextView tvMealTitulo;
CustomFontTextView tvMealPrecio;
CustomFontTextView tvMealDescripcion;
CustomFontTextView tvCantidadComida;
ImageButton botonMasComida;
ImageButton botonMenosComida;
public mealViewHolder(View itemView) {
super(itemView);
tvMealTitulo = (CustomFontTextView) itemView.findViewById(R.id.tvMealTitulo);
tvMealPrecio = (CustomFontTextView) itemView.findViewById(R.id.tvMealPrecio);
tvMealDescripcion= ( CustomFontTextView) itemView.findViewById(R.id.tvMealDescripcion);
tvCantidadComida = (CustomFontTextView) itemView.findViewById(R.id.tvCantidadComida);
botonMasComida = (ImageButton) itemView.findViewById(R.id.botonMasComida);
botonMenosComida = (ImageButton) itemView.findViewById(R.id.botonMenosComida);
}
}
}
Al hacer click
a mi botón para aumentar el contador en el Recyclerview
, actualiza el TextView
de las demás filas si les doy click
en su respectivo botón.