- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在单击按钮时取消 countdountimer 的 onfinish 函数我执行 timer.cancel 但仍然调用 on finish。
running = false;
countDownTimer.cancel();
countDownTimer = null;
finish();
startActivity(i);
这是倒计时
private CountDownTimer createTimer() {
return new CountDownTimer(getIntent().getIntExtra("timer", 5460000),
1000) {
@SuppressLint("NewApi")
public void onTick(long millisUntilFinished) {
timer.setText("Section time: "
+ String.format(
Locale.ENGLISH,
"%d min, %d sec",
TimeUnit.MILLISECONDS
.toMinutes(millisUntilFinished),
TimeUnit.MILLISECONDS
.toSeconds(millisUntilFinished)
- TimeUnit.MINUTES
.toSeconds(TimeUnit.MILLISECONDS
.toMinutes(millisUntilFinished))));
timer_count = (int) millisUntilFinished;
}
public void onFinish() {
if (running) {
int random;
if (getIntent().getIntExtra("t_no", 0) < 20) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.vocab.size() - 11);
i.putExtra("q_no", random);
i.putExtra("t_no", 20);
i.putExtra("answers",
getIntent().getStringExtra("answers"));
countDownTimer.cancel();
countDownTimer = null;
running = false;
finish();
startActivity(i);
} else if (getIntent().getIntExtra("t_no", 0) < 40) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.listining.size() - 4);
i.putExtra("q_no", random);
i.putExtra("t_no", 40);
i.putExtra("answers",
getIntent().getStringExtra("answers"));
countDownTimer.cancel();
countDownTimer = null;
running = false;
finish();
startActivity(i);
} else if (getIntent().getIntExtra("t_no", 0) < 50) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.reading.size() - 1);
i.putExtra("paragraph_id", random + 1);
i.putExtra("q_no", 0);
i.putExtra("t_no", 50);
i.putExtra("answers",
getIntent().getStringExtra("answers"));
countDownTimer.cancel();
countDownTimer = null;
running = false;
finish();
startActivity(i);
} else if (getIntent().getIntExtra("t_no", 0) < 60) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.vid.size() - 1);
i.putExtra("Scene_ID", random + 1);
i.putExtra("q_no", 0);
i.putExtra("t_no", 60);
i.putExtra("answers",
getIntent().getStringExtra("answers"));
countDownTimer.cancel();
countDownTimer = null;
running = false;
finish();
startActivity(i);
} else if (getIntent().getIntExtra("t_no", 0) < 100) {
i = new Intent(getApplicationContext(),
Practice_result.class);
i.putExtra("type", getIntent().getStringExtra("type"));
i.putExtra("answers",
getIntent().getStringExtra("answers"));
countDownTimer.cancel();
countDownTimer = null;
running = false;
finish();
startActivity(i);
}
}
}
}.start();
}
这是我使用倒数计时器的 Activity 的一部分,除了这里我没有在任何地方使用它
else if (getIntent().getStringExtra("type").equalsIgnoreCase("Test")) {
timer.setVisibility(View.VISIBLE);
back.setVisibility(View.INVISIBLE);
running = true;
countDownTimer = this.createTimer();
if (getIntent().getIntExtra("t_no", 0) < 10) {
final ArrayList<HashMap<String, String>> questions = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < 50; i++) {
if (MainActivity.structure.get(i).get("type_p_t")
.equalsIgnoreCase("t"))
questions.add(MainActivity.structure.get(i));
}
main_txt.setText("Q"
+ (getIntent().getIntExtra("t_no", 0) + 1)
+ ": "
+ questions.get(getIntent().getIntExtra("q_no", 0))
.get("question").replace("#", ""));
title.setText("Structure/ Sentence Completion");
opt_a_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[0]);
opt_b_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[1]);
opt_c_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[2]);
opt_d_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[3]);
cor_ans = questions.get(getIntent().getIntExtra("q_no", 0))
.get("cor_ans");
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int random;
if (getIntent().getIntExtra("t_no", 0) == 9) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.structure.size() - 51);
} else {
i = new Intent(getApplicationContext(),
Struct.class);
i.putExtra("type",
getIntent().getStringExtra("type"));
Random r = new Random();
random = r.nextInt(MainActivity.structure.size() - 51);
while (Helper.sec_questions.contains(random)) {
random = r.nextInt(MainActivity.structure
.size() - 51);
}
Helper.sec_questions.add(random);
}
i.putExtra("q_no", random);
i.putExtra("t_no",
getIntent().getIntExtra("t_no", 0) + 1);
if (ans.equalsIgnoreCase(cor_ans)) {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "true#");
} else {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "false#");
}
i.putExtra("timer", timer_count);
Details_data.answers.add(ans);
Details_data.choices.add(opt_a_txt.getText().toString()
+ "#" + opt_b_txt.getText().toString() + "#"
+ opt_c_txt.getText().toString() + "#"
+ opt_d_txt.getText().toString());
Details_data.correct_answers.add(cor_ans);
Details_data.questions.add(main_txt.getText()
.toString());
Details_data.why.add(questions
.get(getIntent().getIntExtra("q_no", 0))
.get("why").replace("#", ""));
running = false;
countDownTimer.cancel();
countDownTimer.onFinish();
countDownTimer = null;
finish();
startActivity(i);
}
});
} else if (getIntent().getIntExtra("t_no", 0) < 20) {
final ArrayList<HashMap<String, String>> questions = new ArrayList<HashMap<String, String>>();
for (int i = 50; i < MainActivity.structure.size(); i++) {
if (MainActivity.structure.get(i).get("type_p_t")
.equalsIgnoreCase("t"))
questions.add(MainActivity.structure.get(i));
}
main_txt.setText("Q"
+ (getIntent().getIntExtra("t_no", 0) + 1)
+ ": "
+ questions.get(getIntent().getIntExtra("q_no", 0))
.get("question").replace("#", ""));
title.setText("Structure/ Error Identification");
opt_a_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[0]);
opt_b_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[1]);
opt_c_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[2]);
opt_d_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[3]);
cor_ans = questions.get(getIntent().getIntExtra("q_no", 0))
.get("cor_ans");
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int random;
if (getIntent().getIntExtra("t_no", 0) == 19) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.vocab.size() - 11);
} else {
i = new Intent(getApplicationContext(),
Struct.class);
i.putExtra("type",
getIntent().getStringExtra("type"));
Random r = new Random();
random = r.nextInt(MainActivity.structure.size() - 51);
while (Helper.sec_questions.contains(random)) {
random = r.nextInt(MainActivity.structure
.size() - 51);
}
Helper.sec_questions.add(random);
}
i.putExtra("q_no", random);
i.putExtra("t_no",
getIntent().getIntExtra("t_no", 0) + 1);
if (ans.equalsIgnoreCase(cor_ans)) {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "true#");
} else {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "false#");
}
i.putExtra("timer", timer_count);
Details_data.answers.add(ans);
Details_data.choices.add(opt_a_txt.getText().toString()
+ "#" + opt_b_txt.getText().toString() + "#"
+ opt_c_txt.getText().toString() + "#"
+ opt_d_txt.getText().toString());
Details_data.correct_answers.add(cor_ans);
Details_data.questions.add(main_txt.getText()
.toString());
Details_data.why.add(questions
.get(getIntent().getIntExtra("q_no", 0))
.get("why").replace("#", ""));
running = false;
countDownTimer.cancel();
countDownTimer.onFinish();
countDownTimer = null;
finish();
startActivity(i);
}
});
} else if (getIntent().getIntExtra("t_no", 0) < 40) {
final ArrayList<HashMap<String, String>> questions = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < MainActivity.vocab.size(); i++) {
if (MainActivity.vocab.get(i).get("type_p_t")
.equalsIgnoreCase("t"))
questions.add(MainActivity.vocab.get(i));
}
main_txt.setText("Q"
+ (getIntent().getIntExtra("t_no", 0) + 1)
+ ": "
+ questions.get(getIntent().getIntExtra("q_no", 0))
.get("question").replace("#", ""));
title.setText("Vocabulary");
opt_a_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[0]);
opt_b_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[1]);
opt_c_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[2]);
opt_d_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[3]);
cor_ans = questions.get(getIntent().getIntExtra("q_no", 0))
.get("cor_ans");
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int random;
if (getIntent().getIntExtra("t_no", 0) == 39) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.listining.size() - 4);
} else {
i = new Intent(getApplicationContext(),
Struct.class);
i.putExtra("type",
getIntent().getStringExtra("type"));
Random r = new Random();
random = r.nextInt(MainActivity.vocab.size() - 11);
while (Helper.sec_questions.contains(random)) {
random = r.nextInt(MainActivity.vocab.size() - 11);
}
Helper.sec_questions.add(random);
}
i.putExtra("q_no", random);
i.putExtra("t_no",
getIntent().getIntExtra("t_no", 0) + 1);
if (ans.equalsIgnoreCase(cor_ans)) {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "true#");
} else {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "false#");
}
i.putExtra("timer", timer_count);
Details_data.answers.add(ans);
Details_data.choices.add(opt_a_txt.getText().toString()
+ "#" + opt_b_txt.getText().toString() + "#"
+ opt_c_txt.getText().toString() + "#"
+ opt_d_txt.getText().toString());
Details_data.correct_answers.add(cor_ans);
Details_data.questions.add(main_txt.getText()
.toString());
running = false;
countDownTimer.cancel();
countDownTimer.onFinish();
countDownTimer = null;
finish();
startActivity(i);
}
});
} else if (getIntent().getIntExtra("t_no", 0) < 50) {
final ArrayList<HashMap<String, String>> questions = new ArrayList<HashMap<String, String>>();
main_txt.setVisibility(View.GONE);
opt_a.setVisibility(View.GONE);
opt_b.setVisibility(View.GONE);
opt_c.setVisibility(View.GONE);
opt_d.setVisibility(View.GONE);
headset.setVisibility(View.VISIBLE);
for (int i = 0; i < MainActivity.listining.size(); i++) {
if (MainActivity.listining.get(i).get("type_p_t")
.equalsIgnoreCase("t"))
questions.add(MainActivity.listining.get(i));
}
main_txt.setText("Q"
+ (getIntent().getIntExtra("t_no", 0) + 1)
+ ": "
+ questions.get(getIntent().getIntExtra("q_no", 0))
.get("question").replace("#", ""));
title.setText("Listening Comprehension");
opt_a_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[0]);
opt_b_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[1]);
opt_c_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[2]);
opt_d_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[3]);
cor_ans = questions.get(getIntent().getIntExtra("q_no", 0))
.get("cor_ans");
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int random;
if (getIntent().getIntExtra("t_no", 0) == 49) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type",
getIntent().getStringExtra("type"));
Random r = new Random();
random = r.nextInt(MainActivity.reading.size() - 1);
i.putExtra("paragraph_id", random + 1);
i.putExtra("q_no", 0);
} else {
i = new Intent(getApplicationContext(),
Struct.class);
i.putExtra("type",
getIntent().getStringExtra("type"));
Random r = new Random();
random = r.nextInt(MainActivity.listining.size() - 4);
while (Helper.sec_questions.contains(random)) {
random = r.nextInt(MainActivity.listining
.size() - 4);
}
Helper.sec_questions.add(random);
i.putExtra("q_no", random);
}
i.putExtra("t_no",
getIntent().getIntExtra("t_no", 0) + 1);
if (ans.equalsIgnoreCase(cor_ans)) {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "true#");
} else {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "false#");
}
i.putExtra("timer", timer_count);
Details_data.answers.add(ans);
Details_data.choices.add(opt_a_txt.getText().toString()
+ "#" + opt_b_txt.getText().toString() + "#"
+ opt_c_txt.getText().toString() + "#"
+ opt_d_txt.getText().toString());
Details_data.correct_answers.add(cor_ans);
Details_data.questions.add(main_txt.getText()
.toString());
running = false;
countDownTimer.cancel();
countDownTimer.onFinish();
countDownTimer = null;
finish();
startActivity(i);
}
});
listen.setVisibility(View.VISIBLE);
mp = new MediaPlayer();
listen.setOnClickListener(new OnClickListener() {
@SuppressLint("SdCardPath")
@Override
public void onClick(View v) {
try {
mp.setDataSource("/mnt/sdcard/qualification/"
+ questions.get(
getIntent().getIntExtra("q_no", 0))
.get("voice") + ".mp3");
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
listen.setVisibility(View.GONE);
}
});
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
mp = null;
main_txt.setVisibility(View.VISIBLE);
opt_a.setVisibility(View.VISIBLE);
opt_b.setVisibility(View.VISIBLE);
opt_c.setVisibility(View.VISIBLE);
opt_d.setVisibility(View.VISIBLE);
headset.setVisibility(View.GONE);
}
});
} else if (getIntent().getIntExtra("t_no", 0) < 60) {
paragraph.setVisibility(View.VISIBLE);
final ArrayList<HashMap<String, String>> questions = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < MainActivity.reading_qst.size(); i++) {
if (MainActivity.reading_qst
.get(i)
.get("paragraph_id")
.equalsIgnoreCase(
String.valueOf(getIntent().getIntExtra(
"paragraph_id", 0) + 1)))
questions.add(MainActivity.reading_qst.get(i));
}
main_txt.setText("Q"
+ (getIntent().getIntExtra("t_no", 0) + 1)
+ ": "
+ questions.get(getIntent().getIntExtra("q_no", 0))
.get("question").replace("#", ""));
title.setText("Reading Comprehension");
opt_a_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[0]);
opt_b_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[1]);
opt_c_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[2]);
opt_d_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[3]);
cor_ans = questions.get(getIntent().getIntExtra("q_no", 0))
.get("cor_ans");
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int random;
if (getIntent().getIntExtra("t_no", 0) == 59) {
i = new Intent(getApplicationContext(),
Practice_intruction.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.vid.size() - 1);
i.putExtra("Scene_ID", random + 1);
i.putExtra("q_no", 0);
} else if (getIntent().getIntExtra("t_no", 0) == 54) {
i = new Intent(getApplicationContext(),
Reading.class);
i.putExtra("type", "Test");
Random r = new Random();
random = r.nextInt(MainActivity.reading.size() - 1);
while (Helper.sec_questions.contains(random)) {
random = r.nextInt(MainActivity.reading.size() - 2);
}
Helper.sec_questions.add(random + 1);
i.putExtra("paragraph_id", random + 1);
i.putExtra("q_no", 0);
} else {
i = new Intent(getApplicationContext(),
Struct.class);
i.putExtra("type",
getIntent().getStringExtra("type"));
i.putExtra("paragraph_id",
getIntent().getIntExtra("paragraph_id", 0));
i.putExtra("q_no",
getIntent().getIntExtra("q_no", 0) + 1);
}
i.putExtra("t_no",
getIntent().getIntExtra("t_no", 0) + 1);
if (ans.equalsIgnoreCase(cor_ans)) {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "true#");
} else {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "false#");
}
i.putExtra("timer", timer_count);
Details_data.answers.add(ans);
Details_data.choices.add(opt_a_txt.getText().toString()
+ "#" + opt_b_txt.getText().toString() + "#"
+ opt_c_txt.getText().toString() + "#"
+ opt_d_txt.getText().toString());
Details_data.correct_answers.add(cor_ans);
Details_data.questions.add(main_txt.getText()
.toString());
running = false;
countDownTimer.cancel();
countDownTimer.onFinish();
countDownTimer = null;
finish();
startActivity(i);
}
});
}
else if (getIntent().getIntExtra("t_no", 0) < 100) {
final ArrayList<HashMap<String, String>> questions = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < MainActivity.vid_qst.size(); i++) {
if (MainActivity.vid_qst
.get(i)
.get("Scene_ID")
.equalsIgnoreCase(
String.valueOf(getIntent().getIntExtra(
"Scene_ID", 0) + 1)))
questions.add(MainActivity.vid_qst.get(i));
}
main_txt.setText("Q"
+ (getIntent().getIntExtra("t_no", 0) + 1)
+ ": "
+ questions.get(getIntent().getIntExtra("q_no", 0))
.get("question").replace("#", ""));
title.setText("Visual Comprehension");
opt_a_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[0]);
opt_b_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[1]);
opt_c_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[2]);
opt_d_txt.setText(questions
.get(getIntent().getIntExtra("q_no", 0)).get("choices")
.split("#")[3]);
cor_ans = questions.get(getIntent().getIntExtra("q_no", 0))
.get("cor_ans");
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (getIntent().getIntExtra("t_no", 0) == 99) {
i = new Intent(getApplicationContext(),
Practice_result.class);
i.putExtra("type",
getIntent().getStringExtra("type"));
} else if (getIntent().getIntExtra("t_no", 0) == 59
|| getIntent().getIntExtra("t_no", 0) == 69
|| getIntent().getIntExtra("t_no", 0) == 79
|| getIntent().getIntExtra("t_no", 0) == 89) {
i = new Intent(getApplicationContext(), Video.class);
i.putExtra("type", "Test");
Random r = new Random();
int random = r.nextInt(MainActivity.vid.size() - 1);
while (Helper.sec_questions.contains(random)) {
random = r.nextInt(MainActivity.vid.size() - 1);
}
Helper.sec_questions.add(random + 1);
i.putExtra("Scene_ID", random + 1);
i.putExtra("q_no", 0);
} else {
i = new Intent(getApplicationContext(),
Struct.class);
i.putExtra("type",
getIntent().getStringExtra("type"));
i.putExtra("q_no",
getIntent().getIntExtra("q_no", 0) + 1);
i.putExtra("Scene_ID",
getIntent().getIntExtra("Scene_ID", 0));
}
i.putExtra("t_no",
getIntent().getIntExtra("t_no", 0) + 1);
if (ans.equalsIgnoreCase(cor_ans)) {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "true#");
} else {
i.putExtra("answers",
getIntent().getStringExtra("answers")
+ "false#");
}
i.putExtra("timer", timer_count);
Details_data.answers.add(ans);
Details_data.choices.add(opt_a_txt.getText().toString()
+ "#" + opt_b_txt.getText().toString() + "#"
+ opt_c_txt.getText().toString() + "#"
+ opt_d_txt.getText().toString());
Details_data.correct_answers.add(cor_ans);
Details_data.questions.add(main_txt.getText()
.toString());
running = false;
countDownTimer.cancel();
countDownTimer.onFinish();
countDownTimer = null;
finish();
startActivity(i);
}
});
}
}
opt_a.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
opt_a_img.setImageResource(R.drawable.ans_sel_yallow);
opt_b_img.setImageResource(R.drawable.ans_sel_white);
opt_c_img.setImageResource(R.drawable.ans_sel_white);
opt_d_img.setImageResource(R.drawable.ans_sel_white);
ans = "a";
next.setVisibility(View.VISIBLE);
paragraph.setVisibility(View.GONE);
}
});
opt_b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
opt_a_img.setImageResource(R.drawable.ans_sel_white);
opt_b_img.setImageResource(R.drawable.ans_sel_yallow);
opt_c_img.setImageResource(R.drawable.ans_sel_white);
opt_d_img.setImageResource(R.drawable.ans_sel_white);
ans = "b";
next.setVisibility(View.VISIBLE);
paragraph.setVisibility(View.GONE);
}
});
opt_c.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
opt_a_img.setImageResource(R.drawable.ans_sel_white);
opt_b_img.setImageResource(R.drawable.ans_sel_white);
opt_c_img.setImageResource(R.drawable.ans_sel_yallow);
opt_d_img.setImageResource(R.drawable.ans_sel_white);
ans = "c";
next.setVisibility(View.VISIBLE);
paragraph.setVisibility(View.GONE);
}
});
opt_d.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
opt_a_img.setImageResource(R.drawable.ans_sel_white);
opt_b_img.setImageResource(R.drawable.ans_sel_white);
opt_c_img.setImageResource(R.drawable.ans_sel_white);
opt_d_img.setImageResource(R.drawable.ans_sel_yallow);
ans = "d";
next.setVisibility(View.VISIBLE);
paragraph.setVisibility(View.GONE);
}
});
back.setOnClickListener(new OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
AlertDialog alert = new AlertDialog.Builder(Struct.this)
.create();
if (alert != null) {
alert.setMessage("Are you sure you want to exit?!");
alert.setCancelable(true);
alert.setButton("Yes",
new DialogInterface.OnClickListener() {
@SuppressLint("NewApi")
public void onClick(DialogInterface dialog,
int id) {
Intent i = new Intent(
getApplicationContext(),
MainMenu.class);
running = false;
if (countDownTimer != null) {
countDownTimer.cancel();
countDownTimer.onFinish();
countDownTimer = null;
}
finish();
startActivity(i);
}
});
alert.setButton2("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
}
});
alert.setCanceledOnTouchOutside(false);
alert.show();
TextView msg = (TextView) alert
.findViewById(android.R.id.message);
if (msg != null)
msg.setTextSize(20);
Button b1 = (Button) alert
.findViewById(android.R.id.button1);
if (b1 != null)
b1.setTextSize(20);
Button b2 = (Button) alert
.findViewById(android.R.id.button2);
if (b2 != null)
b2.setTextSize(20);
}
}
});
paragraph.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
i = new Intent(getApplicationContext(), Reading.class);
i.putExtra("type", getIntent().getStringExtra("type"));
i.putExtra("paragraph_id",
getIntent().getIntExtra("paragraph_id", 0));
i.putExtra("q_no", getIntent().getIntExtra("q_no", 0));
i.putExtra("t_no", getIntent().getIntExtra("t_no", 0));
i.putExtra("answers", getIntent().getStringExtra("answers"));
i.putExtra("timer", timer_count);
i.putExtra("return", true);
startActivity(i);
}
});
}
最佳答案
似乎在任何情况下都会调用 finish()。但是,如果您在取消之前将 running 设置为 false,则您的 finish() 方法不会执行任何操作,因此应该没问题。
running = false;
countdownTimer.cancel();
关于android - 倒计时 onfinish();取消后仍然调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36688159/
为什么不倒计时? var container = document.getElementById('dl'); var seconds = 10; var timer; function count
我已经在网上搜索过,但所有现成的网站都是您指定日期的地方,它会倒计时到该日期。我需要的是可以简单地从“27 分 43 秒”(以这种格式)倒计时到 0,从他们登陆页面时开始,有人有可用的片段吗? 最佳答
我正在使用this plugin进行倒计时。在他的例子中,他正在倒计时澳大利亚国庆日 $(function () { var countdownDate = new Date(); count
所以我是 Perl 的新手,我发现我想编写一个倒计时代码,并且真的很挣扎,我在这里找到了一些代码 http://www.perlmonks.org/bare/?node_id=407922并试图弄清楚
我正在尝试创建倒计时。基本上我有客户下订单的时间(以日期时间格式存储在数据库中,例如“2014-08-14 12:52:09”),我也有完成订单所需的时间(其中要么是小时和分钟“1”45”,要么只是分
我正在使用 Flask 构建一个游戏,其中每一轮都有倒计时时间来完成这一轮。我希望时间值每秒减少 1 并在不重新加载页面的情况下进行更新。倒计时本身使用 time.sleep 等待 1 秒,然后将生成
您将获得一个名为 start_num 的整数。编写一段代码,从start_num开始倒计时到1,倒计时结束后,打印出“Liftoff!”。 我不确定如何执行此操作并一直陷入困境。 这是我在问题开始时提
我想为我的 Android 程序实现一个 java 倒计时器,但我不知道该怎么做。它应该从 60 到 0 计算时间,最后程序应该结束,但用户需要查看还剩多少时间,因此计时器应该始终可见。我设法实现了一
我正在使用 jquery_countdown (http://keith-wood.name/countdown.html) 设置 60 分钟计时器。我知道我可以在时间到期时运行回调函数,但是有没有办
所以我在这个网站上找到了这段代码,但我想更改它的一件事,但我似乎无法弄清楚,所以我需要一些帮助。我想要做的是删除日期中的年份,以便倒计时对应于它所在的年份。 var end = new Date('
所以,我有以下(秒倒计时)井然有序。但!我也尝试在倒计时中添加小时和分钟。理想情况下保持相同的结构,并且只使用纯 JS。我希望输出是: 本次促销事件还剩 X 小时、X 分钟和 X 秒! var cou
最近我正在做电子图书馆的项目,需要为用户阅读的每本书提供倒计时器。 例如,在我的数据库中,“用户”有“100 秒”的信用时间来阅读这本书,并且只有当他们阅读这本书时,时间才会减少。 这是我的代码: g
我有一个倒计时脚本,可以获取实时时间并将其从设定时间中减去。除了除非您刷新页面否则它不会更新这一事实之外,这一切都有效。我的函数底部的 setInterval 指示函数每隔一秒运行一次,但它似乎没有这
在已经运行了几次代码之后,我想再次运行我的代码(倒计时)。 Javascript: var btn1 = document.getElementById('btn1'); function timer
如何让这个倒计时在刷新时不重置倒计时?就像当我单击刷新时它应该继续倒计时而不是再次重置倒计时,从“14d、22h、23m、32s”(刷新)继续到“14d、22、59m、59s”。 通过一些研究我发现我
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我是 python 的新手,正在尝试运行一个函数,该函数将在给定一个变量的情况下倒计时到零,然后倒计时到原始变量。输出应如下所示: >>> functionname(5) 5, 4, 3, 2, 1,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 6 年前。
我的目标很简单: 在我的 xml 文件中,我有一个名为:textView2 的 TextView 。 我需要的是一个倒计时,从 15 倒计时到 0,每过一秒,textview 就会更新(例如:15,1
我想要完成的是实时更新的倒计时...像这样: 6 天(只是几天) 12 小时(1 天内的几个小时) 59 分钟(1 小时内仅几分钟) 59 秒(1 分钟内的几秒) 实现此目的的最佳方法? 最佳答案 您
我是一名优秀的程序员,十分优秀!