Note that there are some explanatory texts on larger screens.

plurals
  1. POCount pressed button quantity
    primarykey
    data
    text
    <p>Actually, this question <code>extends</code> <a href="https://stackoverflow.com/questions/6287116/android-registering-a-headset-button-click-with-broadcastreceiver">this one.</a></p> <p>I want to count quantity of my pressed button from my headphone.</p> <pre><code>if(action == KeyEvent.ACTION_DOWN) { Toast.makeText(context, "Pressed 1 time", Toast.LENGTH_SHORT).show(); } if(action == KeyEvent.ACTION_MULTIPLE) { k = event.getRepeatCount(); if(k == 2) Toast.makeText(context, "Pressed 2 times", Toast.LENGTH_SHORT).show(); if(k == 3) Toast.makeText(context, "Pressed 3 times", Toast.LENGTH_SHORT).show(); if(k&gt;=4) { String a = Integer.toString(k); Toast.makeText(context, "Pressed " + a + " times.", Toast.LENGTH_SHORT).show(); } } </code></pre> <p>But as I press the button, I get Toast "Pressed 1 time". I always get it, system never steps into other <code>if</code>s.</p> <p>How can I solve this?</p> <p>Thanks</p> <p><strong>ADDITION</strong> Still can't work this out. Here's what I do:</p> <pre><code> if(action == KeyEvent.ACTION_DOWN) { k++; try { wait(1000); } catch (InterruptedException e) { e.printStackTrace(); } } if(k == 1) Toast.makeText(context, "Pressed 1 time", Toast.LENGTH_SHORT).show(); if(k == 2) Toast.makeText(context, "Pressed 2 times", Toast.LENGTH_SHORT).show(); if(k == 3) Toast.makeText(context, "Pressed 3 times", Toast.LENGTH_SHORT).show(); if(k&gt;=4) { String a = Integer.toString(k); Toast.makeText(context, "Pressed " + a + " times.", Toast.LENGTH_SHORT).show(); } k = 0; abortBroadcast(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload