我在Android中使用“onTouchListener”作为Button。
B.setOnTouchListener(
new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(G.AN,"ButtonID: "+B.getId());
mEvent = event.getAction();
Log.d(G.AN,"Event: " + mEvent);
H.post(RN);
return false;
}
}
);
“RN”是一个可运行的地方,我想定期检查按钮是否仍按下。但是,当我使用isPressed()函数时,它总是返回“false”
@Override public void run() {
Log.d(G.AN,"ButtonID: "+B.getId());
switch(mEvent) {
case MotionEvent.ACTION_UP:
H.removeCallbacks(RN);
break;
case MotionEvent.ACTION_DOWN:
Delay = 300;
default:
**if(!B.isPressed())** {
Log.d(G.AN,"Button is not pressed");
return;
}
if(!IsIndex) { ........................
isPressed功能真的有效吗?有没有用过这种方式的刺绣?
提前致谢...
答案 0 :(得分:0)
我不确定...也许你应该在ACTION.DOWN上的onTouch-method中调用setpressed(true),在ACTION_UP上调用setpressed(false)
答案 1 :(得分:0)
尝试实现这个:
B.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN ) {
Delay = 300;
return true;
}
else if (event.getAction() == MotionEvent.ACTION_UP ){
H.removeCallbacks(RN);
}
return false;
}
});
你必须导入:
import android.view.MotionEvent;