【发布时间】:2018-06-15 05:16:22
【问题描述】:
我想在倒数计时器完成后将用户 AbcActivity 发送到 XyzActivity。像这样我在 AbcActivity 上设置倒数计时器 5 分钟,当 倒数计时器将为 0 或完成它会自动将用户 AbcActivity 发送到 XyzActivity。
我该怎么做?
`
txtDay = (TextView) findViewById(R.id.txtDay);
txtHour = (TextView) findViewById(R.id.txtHour);
txtMinute = (TextView) findViewById(R.id.txtMinute);
txtSecond = (TextView) findViewById(R.id.txtSecond);
tvEventStart = (TextView) findViewById(R.id.tveventStart);
mButton= (Button) findViewById(R.id.button);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent a= new Intent(Start.this,Timetable.class);
startActivity(a);
}
});
countDownStart();
}
public void countDownStart() {
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
handler.postDelayed(this, 1000);
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
// Please here set your event date//YYYY-MM-DD
Date futureDate = dateFormat.parse("2018-11-4");
Date currentDate = new Date();
if (!currentDate.after(futureDate)) {
long diff = futureDate.getTime()
- currentDate.getTime();
long days = diff / (24 * 60 * 60 * 1000);
diff -= days * (24 * 60 * 60 * 1000);
long hours = diff / (60 * 60 * 1000);
diff -= hours * (60 * 60 * 1000);
long minutes = diff / (60 * 1000);
diff -= minutes * (60 * 1000);
long seconds = diff / 1000;
txtDay.setText("" + String.format("%02d", days));
txtHour.setText("" + String.format("%02d", hours));
txtMinute.setText(""
+ String.format("%02d", minutes));
txtSecond.setText(""
+ String.format("%02d", seconds));
} else {
tvEventStart.setVisibility(View.VISIBLE);
tvEventStart.setText("The event started!");
textViewGone();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
handler.postDelayed(runnable, 1 * 1000);
}
public void textViewGone() {
findViewById(R.id.LinearLayout1).setVisibility(View.GONE);
findViewById(R.id.LinearLayout2).setVisibility(View.GONE);
findViewById(R.id.LinearLayout3).setVisibility(View.GONE);
findViewById(R.id.LinearLayout4).setVisibility(View.GONE);
findViewById(R.id.textViewheader1).setVisibility(View.GONE);
}
}
`
【问题讨论】:
标签: java android android-studio countdown