# How to access active value in controlP5 dropdown list?

**URL:** <https://discourse.processing.org/t/how-to-access-active-value-in-controlp5-dropdown-list/28613>\
**Category:** Libraries\
**Created:** [March 17, 2021, 3:58pm UTC](https://discourse.processing.org/t/how-to-access-active-value-in-controlp5-dropdown-list/28613 "2021-03-17T15:58:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [March 17, 2021, 3:58pm UTC](https://discourse.processing.org/t/how-to-access-active-value-in-controlp5-dropdown-list/28613/1 "2021-03-17T15:58:54Z")

</div>

I’m trying to use the controlP5 dropdown list:

```auto
  dropdown = cp5.addScrollableList("Filter")
    .setPosition(10, 55)
    .setSize(200, 100)
    .setBarHeight(20)
    .setItemHeight(20)
    .addItems(l)
    .setOpen(false)
    // .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST
    ;

```

But when I try to access an element like so

```auto
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?

---

<div class="post-metadata">

**Author:** ![duskvirkus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/duskvirkus/32/12456_2.png) [@duskvirkus](https://discourse.processing.org/u/duskvirkus)\
**Post date:** [March 17, 2021, 7:19pm UTC](https://discourse.processing.org/t/how-to-access-active-value-in-controlp5-dropdown-list/28613/2 "2021-03-17T19:19:56Z")

</div>

`.getItem()` looks like it returns a Map object. See [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html) for more info.

So to fix the bug you would put:

```auto
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:

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

```

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

```auto
String active = dropdown.getItem(int(dropdown.getValue())).get("name");
println(active);

```

---

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [March 19, 2021, 4:43pm UTC](https://discourse.processing.org/t/how-to-access-active-value-in-controlp5-dropdown-list/28613/3 "2021-03-19T16:43:44Z")

</div>

Both of these solutions are really helpful, thanks!
