coolbud012

Handler

Dec 3rd, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. private void counterTimer() {
  2.                 final Handler handler = new Handler();
  3.                 final TextView TvCounter = (TextView) findViewById(R.id.Tv_tys_Counter);
  4.                 final java.util.concurrent.atomic.AtomicInteger n = new AtomicInteger(3);
  5.                 final Context ThisContext = this;
  6.                
  7.                 final Runnable counter = new Runnable() {
  8.                         @Override
  9.                         public void run() {
  10.  
  11.                                 TvCounter.setText(Integer.toString(n.get()));
  12.                                 if (n.getAndDecrement() >= 1)
  13.                                         handler.postDelayed(this, 1000);
  14.                                 else {
  15.                                         TvCounter.setVisibility(View.GONE);
  16.                                         Log.d(tag, "Inside the Else Method of counter");
  17.                                        
  18.                                         Intent calculate = new Intent(ThisContext, FourCalculation.class);
  19.                                         calculate.putExtra("difficulty", mDifficulty);
  20.                                         calculate.putExtra("questionType", mQuestions);
  21.                                         startActivity(calculate);
  22.                                 }
  23.                         }
  24.                 };
  25.                 handler.postDelayed(counter, 1000);
  26.  
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment