Hello All,
Below is example of creating counter in android application.
Create layout for counter.
Here is activity_main.xml is for my counter layout.
</LinearLayout>
Java code for Activity is
MainActivity.java
Enjoy.....
Below is example of creating counter in android application.
Create layout for counter.
Here is activity_main.xml is for my counter layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Large Text" android:textSize="80dp" android:textColor="@android:color/white" android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Java code for Activity is
MainActivity.java
public class MainActivity extends Activity { final MyCount counter = new MyCount(10000, 1000); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MyCount counter = new MyCount(10000, 1000);// instantiate counter counter.start(); } public class MyCount extends CountDownTimer { public MyCount(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); } @Override public void onFinish() { TextView counter = (TextView) findViewById(R.id.textView1); counter.setText("0"); //Do Your code Here after counter finish. } @Override public void onTick(long millisUntilFinished) { TextView counter = (TextView) findViewById(R.id.textView1); counter.setText(String.valueOf(millisUntilFinished / 1000)); } } }
Enjoy.....
No comments:
Post a Comment