cancel
Showing results for 
Search instead for 
Did you mean: 

ScrollList Item Selection

svcguy
Associate III

Hello,

Thanks for TouchGFX! I have the following question:

In a screen I have a swipePageContainer and in that I have a scrollList. The scrollList items are custom containers called listItemContainer. I would like to be able to change the background border color when that item is selected. I've setup the callbacks for item selection and they work. My handlers look like this:

void settingsScreenView::portListItemSelectedHandler(int16_t itemSelected)
{
    int16_t currentIndex = presenter->getPortSelection();
 
    portSelectListListItems[currentIndex].setDeselected();
    portSelectListListItems[itemSelected].setSelected();
 
    presenter->setPortSelection(itemSelected);
}

I'm updating the presenter which knows which is the currently selected item in the list and changing the color in the setSelected/setDeselected methods. This works on the lists where the number of items fit into the view.

For longer lists, this code ends up selecting every nth item where n is the number that fit into the view and further, clicking on any item >n ends up in a crash.

Attached are clips of the behavior.

In short what I'd like is to be able to access all the elements of the scrollList, not just the drawables. I know its for memory performance. But it seems that there should be a way to at least pull the one drawable that is selected to manipulate it (or possibly two - old selection and new selection)

Thanks,

Andy

1 REPLY 1

Hi @svcguy​ 

You should save your selected item and initialize the scroll list in your select handler:

itemSelectedVar = itemSelected;
scrollList1.initialize();

Then the items are being updatet via *UpdateItem. There you should highlight your selected item:

if(itemIndex == itemSelectedVar)
{
	item.setHighlighted(true);
}
else
{
	item.setHighlighted(false);
}

Regards

Dejan​