本文主要是介绍android:监听按钮的长按与松开,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
// 长按触发handlefinal Handler handler = new Handler();final Runnable mLongPressed = new Runnable() {public void run() {// 长按处理AudioRecordManager.getInstance(EventReportActivity.this).startRecord();}};// 手势操作处理mBtnVoice.setOnTouchListener(new View.OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {if (event.getAction() == MotionEvent.ACTION_DOWN)handler.postDelayed(mLongPressed, 1000);if (event.getAction() == MotionEvent.ACTION_UP) {handler.removeCallbacks(mLongPressed);tv_voicehint.setText("");// 放开处理AudioRecordManager.getInstance(EventReportActivity.this).stopRecord();AudioRecordManager.getInstance(EventReportActivity.this).destroyRecord();}return true;}});
这篇关于android:监听按钮的长按与松开的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!