I listen the ‘itemsAdded’ event on a ListView which bind to a SerializedObject. And I want to customize how to create a new element.
I change the SerializedProperty and ApplyModifiedProperties inside the itemsAdded event callback, but actually there create two new element.
Actually I want to customize the ListView to support add ‘SerializeReference’ objects.
So I want to customize the ‘add’ button, when the user click the add, it will show a menu, to choose which class want to create for this list.
This is easy for ReorderableList, but no API for this ListView.
Hello, I don’t think I’m following what you’re trying to do here. Do you not have an implementation of the makeItem on your ListView? Also if you’re adding buttons to add items to your list you should add callbacks to your button that show your menu, etc - or did I miss something?
In 2021.2 there has a new property ‘showAddRemoveFooter’ in ListView: Unity - Scripting API: UIElements.ListView.showAddRemoveFooter
This is a built-in add/remove footer. I don’t need to add a button on my own. This makes the ListView work like the ‘ReorderableList’.
If you want to rely on the ListView code to add the item to the source, you could probably use the itemsAdded or itemsSourceChanged callback. The list view will try to create a default item in the list and you can initialize it in the callback, so you could put the code to open your menu there.
Otherwise, you could hijack the callback by querying the button and changing the clickable event on it by yours.
listView.Q<Button>("unity-list-view__add-button").clickable = new Clickable(() =>
{
//your code.
});
Thanks, I can query the button by ‘unity-list-view__add-button’, that what I am looking for.
Hey ! I’m making a custom UIElement derived from ListView in order to implement a custom add button. From my Add button, I have an object reference. Now I need to update my serializedproperty array with this new value, and propagate the change to my UIElement. Is this something I can do right now or Am i missing a piece ?