项目遇到需要实现按键点击同时,如果按住也能实现连续音量加的效果
本办法是通过按下标志开启线程固定间隔时间发送动作
重写setOnTouchListener事件
btn_bolumeup.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event)
{
Log.d("yj.chen","onTouch");
if(event.getAction() == MotionEvent.ACTION_DOWN) {
Log.d("yj.chen","ACTION_DOWN");
longClicked = true;
btn_bolumeup.setBackgroundResource (R.drawable.haier_pop_btn_nor_m);//
Thread t = new Thread(){
@Override
public void run(){
super.run();
while(longClicked)
{
sendcode = 24;
sendkeyenvet();
try{
Thread.sleep(250);
}catch(InterruptedException e){
e.printStackTrace();
}