简体   繁体   中英

How to add lists to SelectBox in libgdx

I have a selectbox in libgdx , I am trying to add a list of values to it . Is the a way i can add the list such as selectbox.addAll(list1) ?

Due to SelectBox reference the method you are looking for is

    public void setItems(T... newItems)

You can use it for example like this:

    SelectBox.SelectBoxStyle boxStyle = new SelectBox.SelectBoxStyle();
    //creating boxStyle...

    String[] values = new String[]{"value1", "value2", "value3", "value4"};
    SelectBox<String> selectBox = new SelectBox<String>(boxStyle);
    selectBox.setItems(values);

Of course instead of creating the style manually you can use Skin with predefined .json file for this purpose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM