Actually, this question extends this one.
I want to count quantity of my pressed button from my headphone.
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>=4)
{
String a = Integer.toString(k);
Toast.makeText(context, "Pressed " + a + " times.", Toast.LENGTH_SHORT).show();
}
}
But as I press the button, I get Toast “Pressed 1 time”. I always get it, system never steps into other ifs.
How can I solve this?
Thanks
ADDITION
Still can’t work this out. Here’s what I do:
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>=4)
{
String a = Integer.toString(k);
Toast.makeText(context, "Pressed " + a + " times.", Toast.LENGTH_SHORT).show();
}
k = 0;
abortBroadcast();
“multiple duplicate key events have occurred in a row” is the definition of ACTION_MULTIPLE, you are only pressing one button.
Edit:
Oh i see you want to next track on double or back on triple clicks. I suggest implementing a thread. In your KeyEvent.ACTION_DOWN count the key presses. In your thread, let’s say call a wait(500) and check how many times your button have been pressed and act accordingly and set back the counter to 0.