Can I have container widgets inside a ListView?

Can you share more about your setup you are trying to achieve? What Widgets are you trying to put inside a ListView that doesn’t work?

You may have to attach touch event listeners to the ListView and specific children, or subclass it and handle all the touch propagation yourself.

We have a ListView with Layout children and each Layout has an ImageView as a child. We handle the touch events ourselves to both “highlight” the correct ImageView as well as “un-highlight” the ImageView if a touch was cancelled or the touch wasn’t a tap.

// selectedWidget is class member of type ui::Widget
ui::ListView::ccListViewCallback func = [this](cocos2d::Ref* senderRef, cocos2d::ui::ListView::EventType e) {
        dlog("enter listview event");
        auto lv = dynamic_cast<ListView*>(senderRef);
        if(lv) {
            this->selectedIndex = int(lv->getCurSelectedIndex());
            dlog("cur selected index = " PRINTF_ZD "", selectedIndex);

            if(e == ListView::EventType::ON_SELECTED_ITEM_END)
            {
                if(selectedWidget) {
                    selectedWidget->setColor(Color3B::WHITE);
                    selectedWidget = nullptr;
                }

                log("list view selection end");
                auto widget = lv->getCurrentFocusedWidget();
                if(!widget) widget = lv->getItem(selectedIndex);

                if(widget) {
                    widget->setCascadeColorEnabled(true);
                    widget->setColor(Color3B::WHITE);
                    int index = (int)lv->getIndex(widget) - 1;
                    log("index = %d", index);
                    // action
                }

                log("cur selected index = " PRINTF_ZD "", lv->getCurSelectedIndex());
            }
            else if(e == ListView::EventType::ON_SELECTED_ITEM_START)
            {
                log("list view selection start");
                auto widget = lv->getCurrentFocusedWidget();
                if(! widget) widget = lv->getItem(selectedIndex);

                if(widget) {
                    widget->setCascadeColorEnabled(true);
                    widget->setColor(Color3B(200,200,200));

                    auto index = lv->getIndex(widget);
                    CC_UNUSED_PARAM(index);
                    dlog("index = " PRINTF_ZD "", index);
                    
                    selectedWidget = widget;
                }
            }
        }
    };
    listview->addEventListener(func);