I’m working on a project and I’m having some problems to make the list views behave like I want.
I have different UI documents that I’m switching on and off like this:
public void Open(T_Data data = default)
{
docRoot.style.display = DisplayStyle.Flex;
this.data = data;
OnOpen();
}
public void Close()
{
InventoryElement.inventories = new List<InventoryElement>();
OnClose();
docRoot.style.display = DisplayStyle.None;
}
And every time that I switch on a UI document with some list views in it I have this problem.
It doesn’t register the first click on an item of the list, but after that everything works perfectly until I close it.
The code that I use is divided in 2 blocks:
- This one is called at the awake of a “Controller” code
protected void ListViewSetup(ListView list, VisualElement template, SelectionType selectionType,
Action<IEnumerable<object>> onSelectionChange)
{
template.visible = true;
list.makeItem = () => Clone(template, doc.visualTreeAsset);
template.visible = false;
list.fixedItemHeight = template.contentRect.height;
list.selectionType = selectionType;
list.selectionChanged += onSelectionChange;
}
- This one is called on the opening
protected void ListViewOnOpen<K>(ListView list, List<K> items, Action<VisualElement, int, List<K>> bind)
{
list.itemsSource = items;
list.bindItem = (e, i) => { bind(e, i, items); };
list.ClearSelection();
}
Do you have some suggestions?