The focus state of the TextField in the ListView item reappears after scrolling out of the view and back in. When editing the selected TextField and selecting another item to cancel the edit state, if the item is scrolled out of view and then back into view, the TextField’s edit state reappears, while the selection state of the other item still exists. This results in an editing TextField and a selected item being different object. how to resolve this
My code
public void CreateGUI()
{
VisualElement root = rootVisualElement;
m_VisualTree.CloneTree(root);
m_SearchField = root.Q<ToolbarSearchField>("SearchField");
m_ListView = root.Q<ListView>("ListView");
InitListView();
}
private void InitListView()
{
m_ListView.itemsSource = m_Tags;
m_ListView.showAddRemoveFooter = true;
m_ListView.selectionType = SelectionType.Single;
m_ListView.makeItem = ListViewMakeItem;
m_ListView.bindItem = ListViewBindItem;
}
private VisualElement ListViewMakeItem()
{
return m_TagItem.CloneTree();
}
private void ListViewBindItem(VisualElement element, int i)
{
var item = m_Tags[i] as MapTag;
var id = element.Q<Label>("id");
var text = element.Q<TextField>("text");
id.text = item.id.ToString();
text.value = item.name;
element.style.height = 30;
element.userData = m_Tags[i];
return;
}