# Android controlP5 button issue

**URL:** https://discourse.processing.org/t/android-controlp5-button-issue/27001
**Category:** Processing for Android
**Created:** [January 12, 2021, 9:08pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001 "2021-01-12T21:08:35Z")
**Posts on this page:** 13
**Page:** 1

<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: [January 12, 2021, 9:08pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/1 "2021-01-12T21:08:35Z")

</div>

In Android is producing a strange behavior.  
Need to click twice, one for highlight and other to call the action.

Also if a button is highlighted and you press in other part of the screen, the result is that the button highlighted is pressed.

is there any solution for this i saw many topics over google complaining this wrong

thanks in advance

---

<div class="post-metadata">

### Author: ![dovindo](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@dovindo](https://discourse.processing.org/u/dovindo)
#### Post date: [January 18, 2021, 7:12am UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/2 "2021-01-18T07:12:34Z")

</div>

Same here. On desktop in javaMode all works great but on the device the behaviour of the controller CP5 is not consistent.

---

<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: [January 18, 2021, 7:42am UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/3 "2021-01-18T07:42:55Z")

</div>

i am trying to solve it this give some results but not accurate

```auto
void draw() {

 if (mousePressed == true) {
 setLock(controlP5.getController("slider1"), false);

  
  }
  else { 
 
   if (mousePressed == false) {
   setLock(controlP5.getController("slider2"), true);
 }
}
}

```

---

<div class="post-metadata">

### Author: ![acalleja](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@acalleja](https://discourse.processing.org/u/acalleja)
#### Post date: [September 30, 2021, 6:33pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/4 "2021-09-30T18:33:58Z")

</div>

Same here, i tried lot of things, even double clicks, callbacklisteners with no luck…  
In the end, what worked best for me is to check that mouse click is inside button’s position:

```auto
public void mousePressed(){
      if (mouseX >= GUIBut_1.getPosition()[0] && mouseX <= GUIBut_1.getPosition()[0] + GUIBut_1.getWidth() && mouseY >= GUIBut_1.getPosition()[1] && mouseY <= GUIBut_1.getPosition()[1] + GUIBut_1.getHeight()){
          GUITxt_1.setText("BOTON1");
          Audio1.play();
      }
      else if (mouseX >= GUIBut_2.getPosition()[0] && mouseX <= GUIBut_2.getPosition()[0] + GUIBut_2.getWidth() && mouseY >= GUIBut_2.getPosition()[1] && mouseY <= GUIBut_2.getPosition()[1] + GUIBut_2.getHeight()){
          GUITxt_1.setText("BOTON2");
          Audio2.play();
      }
  }

```

---

<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 2, 2021, 12:23am UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/5 "2021-10-02T00:23:22Z")

</div>

@acalleja

Hi I have found solution for this issue 🙂🙂🙂

---

<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 2, 2021, 12:27am UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/6 "2021-10-02T00:27:23Z")

</div>

@acalleja

Read 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: ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)
#### Post date: [August 5, 2022, 7:41pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/7 "2022-08-05T19:41:39Z")

</div>

No, this library also does not work. at least with buttons. I need to touch twice, and if I insert those two lines, most of the times I cannot select different values from a Drop Down list.

---

<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: [August 5, 2022, 9:43pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/8 "2022-08-05T21:43:30Z")

</div>

> [@jhsa](#):
>
> No, this library also does not work. at least

Hi  
I have try it with slider And button it’s working with out issue

---

<div class="post-metadata">

### Author: ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)
#### Post date: [August 5, 2022, 10:11pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/9 "2022-08-05T22:11:00Z")

</div>

Thanks for your answer. I did try it, and I do need to touch it twice to make it do whatever it needs to do. Would you help me find out why? I downloaded the rar file you posted and extracted the folder to the documents/processing/libraries folder. compiled the button example, and the problem was still there.  
If I can’t make this work, I won’t be able to create a gui for my midi controller ☹ I already have done it for windows and would like to create the same for android as well.  
Thank You.

---

<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: [August 6, 2022, 4:07am UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/10 "2022-08-06T04:07:53Z")

</div>

> If I can’t make this work, I won’t be able to create a gui for my midi controller

Have you considered making your own controls; it’s not all that difficult.

---

<div class="post-metadata">

### Author: ![jhsa](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhsa](https://discourse.processing.org/u/jhsa)
#### Post date: [August 6, 2022, 1:09pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/11 "2022-08-06T13:09:31Z")

</div>

Hi, thanks for your answer. I have seen the “Ketai” library that seems to work more or less that way, at least for buttons, but how would I do a drop down list that way? I am a complete beginner with processing. Perhaps on touch screen devices I should rethink the user interface. If you follow the link below, you can download and open the editor I have created (windows only). The iLoopino guitar effects controller project is free for everyone to build, it is not a product, so the editor is not perfect, it is what my limited knowledge allowed me to do 🙂  
But now I would like to edit the controller also over bluetooth. That part I think I have more or less sorted.  
perhaps I would have to use popup lists instead of the drop down boxes. Or learn how to create them, but I will need help with that ☹  
Thanks

> **[iL8 Firmware\_EepromEditor\_294.zip](https://www.dropbox.com/s/td32dvbawx532ee/iL8%20Firmware_EepromEditor_294.zip?dl=0)**
>
> Shared with Dropbox

---

<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: [August 6, 2022, 2:07pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/12 "2022-08-06T14:07:27Z")

</div>

> [@jhsa](#):
>
> I did try it, and I do need to touch it twice to make it do whatever it needs to

Hi  
When you touch twice the button works or the slider with out effects on other buttons I mean is it normal active ON/OFF touch/released ??

With example I provided someone solved the button/slider issue as he said and as happened with me

> [@Solving touch issue](https://discourse.processing.org/t/solving-touch-issue/28152/13):
>
> Thanks for your help. The button problem is solved now. Regards

---

<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: [August 6, 2022, 3:26pm UTC](https://discourse.processing.org/t/android-controlp5-button-issue/27001/13 "2022-08-06T15:26:06Z")

</div>

Unfortunately I don’t have a 64-bit windows box and was unable to run your editor; perhaps a screenshot so I can see what types of controls you are using. Is the android device a phone or a tablet? Is the bluetooth classic or LE? The following source code runs on an android tablet and may be something that you could use. I also have code for simple push buttons and a stepper with up/down arrows.

```auto
/*
 Demonstrates drop down list for Android.
*/

 // Drop Down List control parts => a.)display field, b.)arrow, c.)listItems
final int _displayX = 100;
final int _displayY = 120;
final int _displayW = 500;
final int _displayH = 70;
final int _itemH = 70;
final int _arrwX = _displayX + _displayW;
final int _arrwY = _displayY;
final int _arrwSize = _displayH;

boolean drop;
color BLUE = color(64,124,188);
color GREEN = color(0,126,0);
String[] fruit = {"Apples","Peaches","Oranges","Bananas","Pears"};
int[] _itemY;
int selectedItem = -1;
 
class List {
 
 void press(float mx, float my){
   // arrow touches
   if((mx >= _arrwX) && (mx <= _arrwX+_arrwSize) && (my >= _arrwY) && (my <= _arrwY+_arrwSize)){
   if(drop == true){
     drop = false;
    } else {
    drop = true;
   }
   } // list touches
   if (fruit.length > 0) {
   for(int j = 0; j < fruit.length; j++){
    if((mx >= _displayX) && (mx <= _displayX + _displayW) && (my >= _itemY[j] ) && (my <= _itemY[j] + _itemH)) {
     selectedItem = j;
     drop = false;
    } 
   }
  }
 } 
  
 void displayFieldString(String str) {
  fill(255); // display field background color
  rect(_displayX,_displayY,_displayW,_displayH);
  fill(0); // text color
  textSize(42);
  text(str, _displayX + 10, _displayY + 15, _displayW, _displayH);
 }
  
 void display(){
  // display field
 if(selectedItem == -1){
   displayFieldString("Select fruit:");  
   } else {
   displayFieldString(fruit[selectedItem]);
  }
  // arrow
  fill(255); // arrow background color
  rect(_arrwX, _arrwY, _arrwSize, _arrwSize);
  fill(GREEN); // arrow color
  triangle(_arrwX+5, _arrwY+5, _arrwX+_arrwSize-5, _arrwY+5, _arrwX+_arrwSize/2, _arrwY+_arrwSize-5);
  // listItems
  if (drop == true){
   if (fruit.length > 0) {
   // list items  
   _itemY = new int[fruit.length];
   for(int j = 0; j < fruit.length; j++){
    _itemY[j] = (_displayY + _displayH) + j*_itemH;      
    fill(255);
    rect(_displayX,_itemY[j],_displayW,_itemH);
    fill(0);
    textSize(42);
    text(fruit[j], _displayX + 10, _itemY[j] + 15, _displayW, _itemH);
   }  
  }
 }
 } 
  
}

List list;

void setup() {
 fullScreen();
 orientation(LANDSCAPE);    
 list = new List();
 drop = false;
}

void draw() {
 background(BLUE);  
 list.display();
}

void mousePressed(){
 list.press(mouseX, mouseY);
}

```
