Getting ChildObjects Listview

Hi,

I’m having a hard time getting the childobjects of a listview. So, there are multiple objects in it, visible and not yet visible. When I ask for the size, it returns 5 (those 5 are the visible ones).
I tried to scroll the list view from the bottom item to the top item and store those items but than I face the issue that items from other parts in the listview are recognized. Another method that I tried is to scroll the last item a little bit up, until the new item becomes visible. But here I face the issue that a whole other items text is recognized when the item is scrolled.

The code for the first method:
Within this code, I take the listviews childObjects, iterate through them and store all the textfields. When I do this, some textfields of other items are mixed which makes it unusable.

List AccountList;
	ArrayList<String> AccountArray = new ArrayList<String>();
	String tempAccountInfo = "";
	String AccountType="";
	String LastItem = "";
	String NewLastItem = "N/A";
	List<WebElement> AccountListItems;
	
	AccountList = driver.findElements(getObject("ElementsWithinAccountListView"));
	AccountListItems = AccountList.get(AccountList.size() - 1).findElements(By.className("android.widget.TextView"));
	
	while (!NewLastItem.equals(LastItem)) {
		for (int i=0; i<AccountList.size();i++){
			AccountList = driver.findElements(getObject("ElementsWithinAccountListView"));
			AccountListItems = AccountList.get(i).findElements(By.className("android.widget.TextView"));
			switch (AccountList.get(i).getAttribute("className")){
				case "android.widget.LinearLayout":
					
						if (!AccountListItems.get(0).getText().contains("New ")){
							switch(AccountListItems.get(0).getText()){
							case "Current accounts":
								AccountType = "Current accounts";
								break;
							case "Savings accounts":
								AccountType = "Saving accounts";
								break;
							case "Investments":
								AccountType = "Investments";
								break;
							case "Credit cards":
								AccountType = "Credit cards";
								break;
							case "Other":
								AccountType = "Other";
								break;
							}
						}

					break;
				case "android.widget.RelativeLayout":
					AccountListItems = AccountList.get(i).findElements(By.className("android.widget.TextView"));
					if (AccountListItems.size() == 5 || AccountListItems.size() == 4){
						tempAccountInfo = AccountType;
						for(int j=0; j<AccountListItems.size(); j++){
							
							tempAccountInfo = tempAccountInfo + "|" + AccountListItems.get(j).getText();
							LastItem = AccountListItems.get(2).getText();
							
					    }
						
						switch(AccountType){
						case "Investments":
							if (!(AccountListItems.size() == 5)) { 
								System.out.println(tempAccountInfo);
								AccountArray.add(tempAccountInfo);
							}
							break;
						default: 
							System.out.println(tempAccountInfo);
							AccountArray.add(tempAccountInfo);
							break;
						}
						tempAccountInfo = "";
					}
					break;
			}
		}
		
		driver.swipe(AccountList.get(AccountList.size()-1).getLocation().x + 70, AccountList.get(AccountList.size()-1).getLocation().y, AccountList.get(1).getLocation().x + 70, AccountList.get(1).getLocation().y, 3000);
		Thread.sleep(20000);
		
		AccountListItems = AccountList.get(AccountList.size() - 1).findElements(By.className("android.widget.TextView"));
		try {
			NewLastItem = AccountListItems.get(2).getText();
		} catch (Exception e){
			System.out.println("Not at the end of the listview");
			NewLastItem = "N/A";
		}
		System.out.println("LastItem:" + LastItem);
		System.out.println("NewLastItem:" + NewLastItem);
	}

With the second method, The “My income and expenses” scrolled, even though it is not in the textview.

This is my code for the second method:

protected void swipeToNextElement(String Element) throws Exception{ List AccountList;
	String LastItem;
	String NewLastItem;
	List<WebElement> AccountListItems;
	Boolean loop = true;
	
	
	AccountList = driver.findElements(getObject(Element));
	AccountListItems = AccountList.get(AccountList.size()-1).findElements(By.className("android.widget.TextView"));
	
	LastItem = AccountListItems.get(0).getAttribute("text");
	NewLastItem = AccountListItems.get(0).getAttribute("text");
	driver.swipe(AccountList.get(AccountList.size()-1).getLocation().x + (AccountList.get(AccountList.size()-1).getSize().width / 2), AccountList.get(AccountList.size()-1).getLocation().y, AccountList.get(AccountList.size()-1).getLocation().x + (AccountList.get(AccountList.size()-1).getSize().width / 2), AccountList.get(AccountList.size()-1).getLocation().y - 70, 1000);
	
	while (loop) {
		
		
		if (NewLastItem.equals(LastItem)){
			AccountList = driver.findElements(getObject(Element));
			AccountListItems = AccountList.get(AccountList.size()-1).findElements(By.className("android.widget.TextView"));
			driver.swipe(AccountList.get(AccountList.size()-1).getLocation().x + (AccountList.get(AccountList.size()-1).getSize().width / 2), AccountList.get(AccountList.size()-1).getLocation().y, AccountList.get(AccountList.size()-1).getLocation().x + (AccountList.get(AccountList.size()-1).getSize().width / 2), AccountList.get(AccountList.size()-1).getLocation().y - 70, 1000);
			NewLastItem = AccountListItems.get(0).getAttribute("text");
		} else {
			AccountList = driver.findElements(getObject(Element));
			AccountListItems = AccountList.get(AccountList.size()-1).findElements(By.className("android.widget.TextView"));
			driver.swipe(AccountList.get(AccountList.size()-1).getLocation().x + (AccountList.get(AccountList.size()-1).getSize().width / 2), AccountList.get(AccountList.size()-1).getLocation().y, AccountList.get(AccountList.size()-1).getLocation().x + (AccountList.get(AccountList.size()-1).getSize().width / 2), AccountList.get(AccountList.size()-1).getLocation().y + 70, 1000);
			NewLastItem = AccountListItems.get(0).getAttribute("text");
			loop = false;
		}
	}
	
	System.out.println("NewLastItem: " + NewLastItem);
}

Any help is welcome :smile:

Thanks in advance!