我有一个计时器在LongPress
ImageView
上以秒为单位开始计数。如果计时器在跑步时等于10秒,我想在TextView
中显示一条消息。
这是我的代码:
private View.OnLongClickListener speakHoldListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View pView) {
// Do something when your hold starts here.
VibratMV();
playsounde();
StartAnimation();
txtscanstat.setText(R.string.scanningstat);
txtsavedstat.setText("");
chrono.setText("");
chrono.setVisibility(View.INVISIBLE);
txtscanstat.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.slide_in_left));
txtscanstat.setTextColor(Color.parseColor("#434a54"));
chrono.setTextColor(Color.parseColor("#434a54"));
chrono.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out));
savebtn.setText(R.string.save_btn);
savebtn.setEnabled(true);
isScannerPressed = true;
chrono.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener(){
@Override
public void onChronometerTick(Chronometer cArg) {
long time = SystemClock.elapsedRealtime() - cArg.getBase();
int h = (int)(time /3600000);
int m = (int)(time - h*3600000)/60000;
int s= (int)(time - h*3600000- m*60000)/1000 ;
String ss = s < 10 ? "0"+s: s+"";
chrono.setText(ss);
if(chrono.getText().toString().equals(10)){
txtscanstat.setText("You can");
}
}
});
chrono.setBase(SystemClock.elapsedRealtime());
chrono.start();
return true;
}
};