First of all, sorry for my English and my Android beginner level.

I'll try to sum up:

I have a call to an api from which I pick up an object like this:

    {
    "id": 1,
    "name": "Mesa 1",
    "productosDto": [
        {
            "id": 40,
            "name": "Croquetas",
            "image": "Imagen",
            "price": 5.0
        },
        {
            "id": 54,
            "name": "Croquetas",
            "image": "Imagen",
            "price": 5.0
        },
        {
            "id": 55,
            "name": "Sardinas",
            "image": "Imagen",
            "price": 5.0
        },
        {
            "id": 56,
            "name": "Pizza Yorkeso",
            "image": "Imagen",
            "price": 6.5
        }
    ]
}

And this is the call:

     public void GetMesa(){

        Call<Mesa> call=mesaService.getMesa(Mesaid, "application/json");
        call.enqueue(new Callback<Mesa>() {
            @Override
            public void onResponse(Call<Mesa> call, Response<Mesa> response) {

                for(int i=0;i< response.body().getProductosDto().size();i++)
                {

                    Producto producto= new Producto(response.body().getProductosDto().get(i).getId(),response.body().getProductosDto().get(i).getName(),response.body().getProductosDto().get(i).getImage(),response.body().getProductosDto().get(i).getPrice());

                    productosCliente.add(producto);

                }
                productoAdapter = new ProductoAdapter(MesaActivity.this, R.layout.adapter_producto, productosCliente);
                listaProductosCliente.setAdapter(productoAdapter);
                
            }

            @Override
            public void onFailure(Call<Mesa> call, Throwable t) {
                Log.d("response", t.getMessage());
            }
        });
    }

As you can see, I collect the items of type "Producto", I introduce them in an ArrayList (productosCliente) and add them to a ListView (listaProductosCliente) through an custom adapter.


Everything works fine and this is what I get:

[![introducir la descripción de la imagen aquí][1]][1]


This is where my question comes:


I want to show all the items with the same name in the same row and add a textview with the amount of accumulated objects. Something like that:

[![introducir la descripción de la imagen aquí][2]][2]

Is it possible?


I also add the code of my adapter just in case:

    public class ProductoAdapter extends ArrayAdapter {

    Context context;
    int itemLayout;
    List<Producto> productos;

    public ProductoAdapter(@NonNull Context context, int resource, @NonNull List<Producto> objects) {
        super(context, resource, objects);
        this.context = context;
        itemLayout = resource;
        productos = objects;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater layoutInflater = LayoutInflater.from(context);
            convertView = layoutInflater.inflate(itemLayout, parent, false);
        }

        TextView name = convertView.findViewById(R.id.name);
        TextView price = convertView.findViewById(R.id.price);

        name.setText(productos.get(position).getName());

        String priceSTR = String.valueOf(productos.get(position).getPrice());
        price.setText(priceSTR);

        return convertView;
    }

Thank you! Gracias!


  [1]: https://i.sstatic.net/EljVu.png
  [2]: https://i.sstatic.net/fPLmL.png