想要释放按钮,已经实现了onLongClick()
和onClick()
侦听器,它们工作正常,但是如何检测Release。实际上想要创建一个类似于WhatsApp音频录制按钮的按钮,如果短按或触摸没有任何作用,则长时间按住会开始录制音频,并在释放[[stops录制时。
@Override
public void onClick(View v) {
shortClick();
}
});
btn.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
longClick();
return true;
}
});
功能
public void shortClick()
{
Toast.makeText(this, "Short click Cancel !!!", Toast.LENGTH_SHORT).show();
}
public void longClick()
{
Toast.makeText(this, "Long click started - Recording started !!!", Toast.LENGTH_SHORT).show();
}
因此,需要释放功能。
@Override
public boolean dispatchKeyEvent(KeyEvent KEvent)
{
int keyaction = KEvent.getAction();
if(keyaction == KeyEvent.ACTION_DOWN)
{
int keycode = KEvent.getKeyCode();
int keyunicode = KEvent.getUnicodeChar(KEvent.getMetaState() );
char character = (char) keyunicode;
System.out.println("DEBUG MESSAGE KEY=" + character + " KEYCODE=" + keycode);
}
return super.dispatchKeyEvent(KEvent);
}