8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ui::ListViewのリスト内で選択した行を取得する

Posted at

CocosStudioのUIEditorで作ったListViewを使うの続きです。
配置したリストの行選択のイベントを拾う方法になります。

デモ

a295046bf0065399464c5fe9100335e0.gif

ソースコード

HelloWorldScene.cpp
    listView->addEventListener([](Ref *ref, ui::ListView::EventType eventType){
        if (eventType == ui::ListView::EventType::ON_SELECTED_ITEM_END) {
            auto listView = static_cast<ui::ListView*>(ref);
            // 選択状態を色を元に戻す
            for (auto widget : listView->getItems()) {
                widget->getChildByName<ui::Text*>("Label_2")->setColor(Color3B::WHITE);
            }
            // 選択した行の色を変える
            auto selectedIndex = listView->getCurSelectedIndex();
            listView->getItem(selectedIndex)->getChildByName<ui::Text*>("Label_2")->setColor(Color3B::GREEN);
            
            CCLOG("selected index %ld", selectedIndex);
        }
    });

GitHubに公開しているソースはこちらになります。

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?