CountDownTimer complete detailed example, countdowntimer example

Source: Internet
Author: User

CountDownTimer complete detailed example, countdowntimer example
MainActivity is as follows:

Package cc. cv; import android. OS. bundle; import android. OS. countDownTimer; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. app. activity;/*** Demo example: * CountDownTimer complete and detailed example * the code is very simple, directly read the comments. ** CountDownTimer is the countdown introduced by Android4.0 */public class MainActivity extends Activity {private Button mStartButton; private Button mCancelButton; private parameter; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init ();} private void init () {mCountDownTimerSubClass = new CountDownTimerSubClass (15*1000,100 0); mStartButton = (Button) findViewById (R. id. startButton); // starts countdown to mStartButton. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View view) {mCountDownTimerSubClass. start () ;}}); // cancels the countdown. // when CountDownTimer's start is called again, the countdown starts again. mCancelButton = (Button) findViewById (R. id. cancelButton); mCancelButton. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View view) {mCountDownTimerSubClass. cancel () ;}});} private class CountDownTimerSubClass extends CountDownTimer {/*** millisInFuture countdown time * interval between countDownInterval counts every two times */public limit (long millisInFuture, long countDownInterval) {super (millisInFuture, countDownInterval);}/*** countdown ends */@ Overridepublic void onFinish () {System. out. println ("end");}/*** this method is triggered at every countdown time point * millisUntilFinished indicates the remaining time of the entire countdown */@ Overridepublic void onTick (long millisUntilFinished) {long remainedSeconds = millisUntilFinished/1000; System. out. println ("remaining:" + remainedSeconds + "s ");}}}

Main. xml is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    >    <Button        android:id="@+id/startButton"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_marginTop="100dp"        android:text="start" />             <Button        android:id="@+id/cancelButton"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_below="@id/startButton"        android:layout_marginTop="100dp"        android:text="cancel" /></RelativeLayout>



Use the learned physical knowledge to complete the spaces in the following table, in the form of an example.

The water vapor in the air around the refrigerator door is cooled and liquefied into small water beads, and hot water. After the evaporation of hot water, the cold air is liquefied into small water beads, that is, white gas ,,,,,,,,,,, the temperature of the filament is extremely high. cooling glass wall condensation after filament Sublimation

The values at the position are 12 in both directions. The value at the position is equal to + on the left. The complete matrix is output in the program language and the sample code is provided,

Except that each number at the end of the first line is the sum of the numbers at the left and top.
The command line window width is 80 characters by default, so the output format is messy.
It is best to create a winform project.

1. console Program
Class Program
{
Static void Main (string [] args)
{
Int [,] array = new int [12, 12];
Array [0, 0] = 1;

For (int I = 1; I <12; I ++)
{
Array [0, I] = I + 1;
Array [I, 0] = I + 1;
}

For (int I = 1; I <12; I ++)
{
For (int j = 1; j <12; j ++)
{
Array [I, j] = array [I-1, j] + array [I, j-1];
}
}
System. Text. StringBuilder B = new StringBuilder ();
B. AppendLine ("output result ");
For (int I = 0; I <array. GetLength (0); I ++)
{
For (int j = 0; j <array. GetLength (1); j ++)
{
B. Append (array [I, j]. ToString () + "\ t ");
}
B. AppendLine ();
}
B. AppendLine ("OK ");
Console. Write (B );
Console. Read ();
}
}
2. winform Program
Create a new form, drag a button and a textbox
Private void button#click (object sender, EventArgs e)
{
This. button1.Anchor = AnchorStyles. Top | AnchorStyles. Right;
This. WindowState = FormWindowState. Maximized;
This. textBox1.Multiline = true;
This. textBox1.Dock = DockStyle. Fill;
This. button1.BringToFront ();
Int [,] arra ...... remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.