gpt4 book ai didi

java - Android 上发布 onLongClickListener

转载 作者:行者123 更新时间:2023-12-02 03:54:29 25 4
gpt4 key购买 nike

我有一个按钮。当用户按住按钮时,我想要录制视频。当用户释放按钮时,我想添加一些代码来处理视频并停止录制,但是如何检测用户何时释放按钮并且 onLongClickListener 执行完毕?

snap.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
try {
initRecorder(mCameraView.getHolder().getSurface());
mMediaRecorder.start();
try {
Thread.sleep(10 * 1000); // This will recode for 10 seconds, if you don't want then just remove it.
} catch (Exception e) {
e.printStackTrace();
}
finish();
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
});

最佳答案

我已经为您准备了一个 fragment ,请看一下 https://gist.github.com/0x0af/013c4e7a90a481e04f77#file-snippet-java .

基本上,您要做的就是实现 View.OnTouchListener() 并等待 MotionEvent.ACTION_DOWN 和 MotionEvent.ACTION_UP

更新:使用计时器来确定操作是否是长按

关于java - Android 上发布 onLongClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35616277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com