I have an ArrayList<Menu> in my App, the Menu object looks like:
public class Menu {
public int id;
public String desc;
public boolean opzionale;
public int limite;
public List<Prodotti> prodotti;
}
On the user selection i show in my RecyclerView prodotti. each Prodotti on user action can be modified but have to be modified only at the specific position of ArrayList<Menu>.
So initially i just show items at the first position of the Array like:
List<Menu.Prodotti> listProdotti = listMenu.get(fase).prodotti;
fase is a dynamic value which specify which items of which Menu has to be shown.
Then in another function i change the value of the Prodotto at position like:
Menu.Prodotti prodotto = listProdotti.get(position);
prodotto.setQta(qtaProdotto + qta);
The issue is that after doing so all prodotti of ArrayList<Menu> at position will update it's quantity.
So if in my array i have data like:
ArrayList<Menu.Prodotti> prodotti = new ArrayList<>();
prodotti.add(new Menu.Prodotti("TEST1", "1", 0, 0, 1, 0));
prodotti.add(new Menu.Prodotti("TEST2", "2", 0, 0, 1, 0));
prodotti.add(new Menu.Prodotti("TEST3", "3", 0, 0, 1, 0));
prodotti.add(new Menu.Prodotti("TEST4", "4", 0, 0, 1, 0));
prodotti.add(new Menu.Prodotti("TEST5", "5", 0, 0, 1, 0));
ArrayList<Menu> listMenu = new ArrayList<>();
listMenu.add(new Menu(1, "Fase 1", false, 1, prodotti));
listMenu.add(new Menu(2, "Fase 2", false, 1, prodotti));
listMenu.add(new Menu(3, "Fase 3", false, 1, prodotti));
listMenu.add(new Menu(4, "Fase 4", true, 2, prodotti));
And i change the listMenu.get(0).prodotti.get(1).setQta(2) ALL the products in the listMenu at position 1 will be set with Qta 2.
All my logics are in RecyclerView.Adapter.

