I am creating an Android app and using Volley to get a webpage by making post request. And using Jsoup for parsing HTML code. I used Jsoup selecter to filter and extract needed data. And then I split data and store in an String array. Finally, I'm looping string arrays and storing all data in Array list.
Now the problem is, the data is form of labels and values and I've inserted data in array list like (at first index "label" and at second index "value") But the array list order is not correct. It outputs:
[Label 1, Label 2, Label 3, Label 4, Label 5, Value 5, Value 4, Value 3, Value 2, Value 1]
So the first label is at first index and first value is at last index. Maybe there's something wrong OR missing.
I have created simple example scenario in Java and here is the example code:
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<>();
String labels = "Label 1: Label 2: Label 3: Label 4: Label 5";
String values = "Value 1\n Value 2\n Value 3\n Value 4\n Value 5\n";
String[] labelsArray = labels.split(":");
String[] valuesArray = values.split("\n");
for(int i = 0; i < labelsArray.length; i++){
arrayList.add(i, labelsArray[i]);
arrayList.add(i+1, valuesArray[i]);
}
System.out.println(arrayList.toString());
}
PS: I can apply a small tweak to make it work but I wanted to know; what is the actual problem.
add(0, Label); add(1, Value)then you doadd(1, Label); add(2, Value);thenadd(2, Label); add(3, Value);etc.