如何在长按后检测按钮的释放?

问题描述 投票:0回答:1

想要释放按钮,已经实现了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(); }
因此,需要释放功能。

android whatsapp touch-event
1个回答
0
投票
这是工作代码

@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); }

© www.soinside.com 2019 - 2024. All rights reserved.