其实这个问题extends
这个。
我想从我的耳机计算我按下按钮的数量。
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();
}
}
但是当我按下按钮时,我得到 Toast “Pressed 1 time”。我总是明白,系统从不进入其他if
s。
我该如何解决这个问题?
谢谢
添加 仍然无法解决这个问题。这就是我所做的:
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();