How to access active value in controlP5 dropdown list?

I’m trying to use the controlP5 dropdown list:

  dropdown = cp5.addScrollableList("Filter")
    .setPosition(10, 55)
    .setSize(200, 100)
    // .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST

But when I try to access an element like so

dropdownActive = dropdown.getItem(1);

I get the error message Type mismatch, "java.util.Map<java.lang.String,java.lang.Object>" does not match with "int"

How can I access the active dropdown value?

.getItem() looks like it returns a Map object. See for more info.

So to fix the bug you would put:

Map<String, Object> element = dropdown.getItem(1);

But based on what you said I don’t think that’s what you’re looking for. To get the index of the element that was clicked most recently you would use .getValue() (which for some unknown reason returns a float). So I think it would look like:

int active = int(dropdown.getValue()));

To get the name of the item that was clicked last you could use:

String active = dropdown.getItem(int(dropdown.getValue())).get("name");
1 Like

Both of these solutions are really helpful, thanks!