-1
我正在寫一個Android應用程序,其中使用了定時器android。它正在完美地工作,現在我想讓它像每秒振動直到完成時間。在Android中每秒鐘使用計時器進行振動
下面我的代碼給出:
public class TimerActivity extends Activity {
Button btnStart, btnStop;
TextView textViewTime;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_responders_timer);
btnStop = (Button)findViewById(R.id.CanelButton);
textViewTime = (TextView)findViewById(R.id.textViewTime);
textViewTime.setText("10");
textViewTime.setTextSize(120);
final CounterClass timer = new CounterClass(10000,1000);
textViewTime.setTextSize(120);
timer.start();
btnStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
timer.cancel();
}
});
}
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
public class CounterClass extends CountDownTimer {
public CounterClass(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
textViewTime.setTextSize(50);
textViewTime.setText("Completed.");
}
@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onTick(long millisUntilFinished) {
textViewTime.setText(""+millisUntilFinished/1000);
}
}
讓我谷歌認爲你: 'Android的震動'= HTTP ://stackoverflow.com/questions/13950338/how-to-make-an-and roid-device-vibrate嚴重的是,學習搜索。 – adelphus 2014-12-27 14:17:00