Зная индекс ребенка, которого вы хотите заменить (возможно, вызвав getWidgetIndex(...)
), вы можете заменить этот виджет на новый, например, так:
StackPanel sp = new StackPanel();
// ... you are setting up your StackPanel etc
// when you want to replace a widget
int index = sp.getWidgetIndex(widgetYouWantToReplace);
if (index != -1) {
sp.insert(newWidget, index);
}
sp.remove(widgetYouWantToReplace);