There is a class itemList
public class itemList implements Serializable { public String nameList; public String Tag; public ArrayList<itemQuestion> itemQuestions; public itemList(String nameList, String Tag,ArrayList<itemQuestion> itemQuestions) { this.nameList = nameList; this.Tag = Tag; this.itemQuestions = itemQuestions; } } It has an array with the itemQuestion class itemQuestion
public class itemQuestion implements Serializable { public String question; public ArrayList<itemAnswer> answer; public int quantityTrue; public int quantityFalse; public itemQuestion(String question,ArrayList<itemAnswer> answer, int quantityTrue, int quantityFalse) { this.question = question; this.answer = answer; this.quantityTrue = quantityTrue; this.quantityFalse = quantityFalse; } } And in the itemQuestion class itemQuestion there is another array with itemAnswer
public class itemAnswer implements Serializable { public String Answer; public boolean trueAnswer; public itemAnswer (String Answer, boolean trueAnswer) { this.Answer = Answer; this.trueAnswer = trueAnswer; } } So, basically, there is a variable with the itemList class
public itemList itemListS = new itemList("","arif",new ArrayList<itemQuestion>()); I add a new item to the itemListS element of its itemQuestions array itemQuestions
public ArrayList<itemAnswer> answer = new ArrayList<itemAnswer>(); //... Здесь заполняю массив answer и т.д. ... // itemListS.itemQuestions.add(new itemQuestion(ArifEditText.getText().toString().toLowerCase(), answer, 0, 0)); answer.clear(); And the whole problem is that when, for example, I add a new element to the itemQuestions array, then the elements that already exist in the array take on the value of the answer of the element that was added last.
(Schematic examples will go on, so it’s not necessary to write that I fill the array in the wrong way, etc.)
For example: Suppose that this is an array before filling
// ... Первый элемент ... // question = "150" ArrayList<itemAnswer> answer = {1 false, 0 false, 6 false, 5 false}; quantityTrue = 0; quantityFalse = 0; And here I add the second element
// ... Первый элемент ... // question = "150" ArrayList<itemAnswer> answer = {2 false, 5 false, 8 false, 7 false}; quantityTrue = 0; quantityFalse = 0; // ... Второй элемент ... // question = "200" ArrayList<itemAnswer> answer = {2 false, 5 false, 8 false, 7 false}; quantityTrue = 0; quantityFalse = 0; And as you can see, the array of the first element's answer takes the value of the second element's answer , I think explained is available.
finalin all signatures - Senior Pomidoranswer, but doanswer.clear()and fill it with new elements? - zRrr