cancel
Showing results for 
Search instead for 
Did you mean: 

How to programmatically scroll up and down a scrollList

I want to programmatically scroll up and down a scrollList. I want a button push or something in the application to trigger scrolling up or down one item or 1 page.
The goal is a list of error codes. Right now they are just strings with numbers between 1 and 6.
I tried it with animateToItem, but I get strange behavior.
My list has 3.5 items visible, so 4 drawable items. The array scrollListListItems generated by TouchGFX is 5 drawable items.
It has up to 6 items in the list. But the number is variable (I used checkmarks to add or remove items from the list).
If I shorten my list to 5 items no scrolling happens programmatically.
The indexes of the items are not in order in the drawables. For instance 5,1,2,3,4.

void ErrorScreenView::scrollUpFunction(void)
{	
	int16_t minIndex = INT16_MAX;
	int16_t maxIndex = -1;

	for (int i = 0; i < scrollListListItems.getNumberOfDrawables(); i++)
	{
		int16_t itemIndex = scrollList.getItem(i);

		if (itemIndex >= 0)
		{
			minIndex = std::min(minIndex, itemIndex);
			maxIndex = std::max(maxIndex, itemIndex);
		}
	}


	if (minIndex > 0)
	{
		scrollList.animateToItem(minIndex - 1);
	}

}

void ErrorScreenView::scrollDownFunction(void)
{	
	int16_t minIndex = INT16_MAX;
	int16_t maxIndex = -1;

	for (int i = 0; i < scrollListListItems.getNumberOfDrawables(); i++)
	{
		int16_t itemIndex = scrollList.getItem(i);

		if (itemIndex >= 0)
		{
			minIndex = std::min(minIndex, itemIndex);
			maxIndex = std::max(maxIndex, itemIndex);
		}
	}

	if (maxIndex < (scrollList.getNumberOfItems() - 1))
	{
		scrollList.animateToItem(maxIndex + 1);
	}
}

 

Other functionality of the list I got working:

  • clickable items, selecting it selects it with a box, this is preserved when scrolling
  • removing items from the list, the list resizes and refreshes (invalidates)

When scrolling programmatically these two functions don't work properly either. Clicking an item selects the wrong one and old items can linger unless I scroll manually.

Is there a way to programmatically trigger what works fine with touch?

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
0 REPLIES 0