# controlP5 Button solution for android / adpe

**URL:** <https://discourse.processing.org/t/controlp5-button-solution-for-android-adpe/43102>\
**Category:** Processing for Android\
**Created:** [October 31, 2023, 4:14am UTC](https://discourse.processing.org/t/controlp5-button-solution-for-android-adpe/43102 "2023-10-31T04:14:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon15123282](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anon15123282](https://discourse.processing.org/u/anon15123282)\
**Post date:** [October 31, 2023, 4:14am UTC](https://discourse.processing.org/t/controlp5-button-solution-for-android-adpe/43102/1 "2023-10-31T04:14:54Z")

</div>

Here a solution for the weird behavior of the buttons from controlP5 on Android/adpe where you have to click twice to actually click the button.

This solution works with a single click and also with sliding the finger onto the Button and releasing.

The Button highlight is still a problem since if have no clue how to use the setColor() for the Button.  
I’d appreciate any help on that one…  
edit: figured out how to use the clor optionand added that to the first button

But when using an image for the button its not visible 😉

here’s the code:

```auto

/*
  controlP5 button workaround for android/adpe
  by AmyS3
*/

import controlP5.*;

ControlP5 cp5;
CallbackListener cb;
String pbp=null;// we use those tho hold the button name
String pbp2=null;
color btncolor = color(#123456);

void setup()
{
  fullScreen();
  background(255);

  cp5 = new ControlP5(this);
  // make a few buttons to test
  cp5.addButton("b1")// that's the name we use to know which button is pressed
    .setCaptionLabel("Button 1")
    .setPosition(100, 100)
    .setSize(200, 50)
    .setColorBackground(btncolor)
    .setColorForeground(btncolor)
    .setColorActive(btncolor)
    ;

  cp5.addButton("b2")
    .setCaptionLabel("Button 2")
    .setPosition(100, 160)
    .setSize(200, 50)
    ;

  cp5.addButton("b3")
    .setCaptionLabel("Button 3")
    .setPosition(100, 220)
    .setSize(200, 50)
    ;

  //create a custom callbacklistener
  cb = new CallbackListener() {
    public void controlEvent(CallbackEvent theEvent) {
      switch(theEvent.getAction()) {
        case(ControlP5.ACTION_ENTER):
        // here we get the Button name when sliding in, or first click on this button
        pbp=theEvent.getController().getName();
        break;
        case(ControlP5.ACTION_CLICK):
        pbp2=theEvent.getController().getName();
        if (pbp==null)
        {// this gets fired when clicking the same button twice
          click(pbp2);
        }
        break;
        case(ControlP5.ACTION_LEAVE):
        // clear the pbp when sliding out, so we don't click outside the button
        pbp=null;
        break;
      }
    }
  };
  // add the above callback to controlP5
  cp5.addCallback(cb);
}

void draw()
{
  // this is for a first click or sliding in
  // and it needs to be in the draw() or it won't work
  // when using the mouseReleased() its not working
  if (!mousePressed&&pbp!=null)
  {
    click(pbp);
  }
}

void click(String btn)
{
  // here you can put your actual clicking code
  // you get the button name (eg. b1) and use that to discern
  // with if's or switch case.. etc.
/*
  for example:
  if(btn=="b1")
  {
     awesomefunction()
  }
*/
  pbp=null;// clear the name holder's
  pbp2=null;
  println(btn);// and action...
}

```

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [October 31, 2023, 5:32am UTC](https://discourse.processing.org/t/controlp5-button-solution-for-android-adpe/43102/2 "2023-10-31T05:32:23Z")

</div>

If I recall correctly there have been problems with using ControlP5 controls with Android. A couple of references follow for controls that were specifically made for Android:

[https://github.com/vsquared/AndroidWidgets\_Processing4](https://github.com/vsquared/AndroidWidgets_Processing4)

[https://github.com/EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android](https://github.com/EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android)

---

<div class="post-metadata">

**Author:** ![anon15123282](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anon15123282](https://discourse.processing.org/u/anon15123282)\
**Post date:** [October 31, 2023, 8:06am UTC](https://discourse.processing.org/t/controlp5-button-solution-for-android-adpe/43102/3 "2023-10-31T08:06:15Z")

</div>

Yes, ControlP5 has issues, thats why i posted my workaround in case someone is interested.

i had a quick a look at the two other options that you posted and they look nice.  
thanks for that!

but they seem to miss one feature that i really like from cP5… the “group” option, to quickly hide/toggle between groups of controlls. very usefull for multipaged ui’s.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 31, 2023, 11:34am UTC](https://discourse.processing.org/t/controlp5-button-solution-for-android-adpe/43102/4 "2023-10-31T11:34:46Z")

</div>

Hi

Look at this

> [@Solving touch issue](https://discourse.processing.org/t/solving-touch-issue/28152):
>
> the controlP5 library works fine on pc but on android smartphones there is touch issue the sliders conflicted with each other because using touch not mouse for instance if you drag slider bar and left it then touch else where on lcd the slider still activated and change its position i made my first project for android but i was using pc when i transferred to android on my tablet i was shocked did not expected the slider issue after month of searching i find how to make it done i have found o…

---

<div class="post-metadata">

**Author:** ![anon15123282](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anon15123282](https://discourse.processing.org/u/anon15123282)\
**Post date:** [November 1, 2023, 1:52am UTC](https://discourse.processing.org/t/controlp5-button-solution-for-android-adpe/43102/5 "2023-11-01T01:52:34Z")

</div>

i found this one too after searching due to the controlP5 bugs, but skatolo is not working on adpe.

it does not compile.  
apde is complaining:  
**skatolo-dex.jar is mentioned in export.txt,  
but it’sa big fat lie and does not exist.**

hence my workaround for cp5 which does compile on adpe.  
maybe skatalo works on processing for the pc, but i only have a smartphone and no pc…

**edit:** nevermind… i just managed to dex the library and it works now. which is great and embarrassing at the same time…

so thank you for somehow pushing me to try skatalo again… 😉
