The first element of the mass takes the meaning of the last element of the mass



  • Got 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&lt;itemQuestion&gt; itemQuestions)
    {
        this.nameList = nameList;
        this.Tag = Tag;
        this.itemQuestions = itemQuestions;
    }
    

    }

    There's a mass of class in it. itemQuestion

    public class itemQuestion implements Serializable
    {
    public String question;
    public ArrayList<itemAnswer> answer;
    public int quantityTrue;
    public int quantityFalse;

    public itemQuestion(String question,ArrayList&lt;itemAnswer&gt; answer, int quantityTrue, int quantityFalse)
    {
        this.question = question;
        this.answer = answer;
        this.quantityTrue = quantityTrue;
        this.quantityFalse = quantityFalse;
    }
    

    }

    In class itemQuestion There's another mass with class. 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 activate is a class variable. itemList

    public itemList itemListS = new itemList("","arif",new ArrayList<itemQuestion>());

    I add to the element. itemListS to its mass itemQuestions new element

    public ArrayList<itemAnswer> answer = new ArrayList<itemAnswer>();

    //... Здесь заполняю массив answer и т.д. ... //

    itemListS.itemQuestions.add(new itemQuestion(ArifEditText.getText().toString().toLowerCase(), answer, 0, 0));

    answer.clear();

    And the problem is, when, for example, adding a new element to the mass. itemQuestionsthe elements that already exist in the mass take the answer to the element that was added to the latter.

    (There's some schematic examples going on, so don't write that I'm not filling up.

    For example: Let's say it's a lot to fill.

    // ... Первый элемент ... //
    question = "150"
    ArrayList<itemAnswer> answer = {1 false,
    0 false,
    6 false,
    5 false};
    quantityTrue = 0;
    quantityFalse = 0;

    And then 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 mass answer of the first element answer Second element, I think I explained it.



  • It's kind of weird, but after a day of frost, it's all decided somehow.

    final ArrayList<itemAnswer> answers = new ArrayList<itemAnswer>();
    
        for (int i=0; i&lt;answer.size(); i++)
        {
            answers.add(new itemAnswer(answer.get(i).Answer, answer.get(i).trueAnswer));
        }
    
        final itemQuestion itemQuestionAdd = new itemQuestion(ArifEditText.getText().toString().toLowerCase(), answers, 0,0);
    
        itemListS.itemQuestions.add(itemQuestionAdd);
        itemListS.nameList = nameList.getText().toString();
    

    Even if I'm just gonna set it up. final answers = answer It doesn't work.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2