很长一段时间后,我终于知道如何在按下按钮时更新进度条。此代码不适用于姜饼。和所有其他操作系统都可以正常工作。如果您有任何问题,请尽情享受!!!!
button.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if(arg1.getAction()==MotionEvent.ACTION_DOWN){
arg0.post(rotationRunnable);
}
return false;
}
});
RotationRunnable 方法:-
private Runnable rotationRunnable = new Runnable() {
@Override
public void run() {
if (button.isPressed()) {
try{
if(mProgressStatus<100){
Thread.sleep(500);
mProgressStatus = doWork();
pB.setProgress(mProgressStatus);
}
}catch(Exception e) {
e.printStackTrace();
}
button.postDelayed(rotationRunnable, 40);
}
}
};
最后是 DoWork 方法:-
private int doWork() {
// TODO Auto-generated method stub
Timer t=new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
mProgressStatus=mProgressStatus+1;
}
}, 1000);
time=mProgressStatus;
return mProgressStatus;
}