Android Combat Simple Tutorial-41st gun (show Countdown button-for obtaining verification code)

Source: Internet
Author: User

Recently in the function of obtaining verification code, taking into account the excellent user experience, decided to make a countdown prompt button buttons, on-line check some information, very simple can be achieved, I wrote a small demo, we can apply to their own projects.

1.activity_main.xml:

<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/btn_time"        android:layout_width= "wrap_content"        android:layout_ height= "Wrap_content"        android:text= "Get Verification Code"/></relativelayout>

2.mainactivity.java:

Package Com.example.timebutton;import Android.app.activity;import Android.os.bundle;import Android.os.countdowntimer;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.widget.button;public class Mainactivity extends Activity {private Button Mtimebutton;private timecount time; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); requestwindowfeature (Window.feature_no_title); Setcontentview (R.layout.activity_main); Mtimebutton = (Button) Findviewbyid (r.id.btn_time); time = new Timecount (60000, n); Mtimebutton.setonclicklistener ( New Onclicklistener () {@Overridepublic void OnClick (View v) {Time.start ();}});}            /** * Inherit Countdown class * * @author TML * */class Timecount extends Countdowntimer {/** * Construction method * * @param millisinfuture *  Total Countdown long milliseconds * @param countdowninterval * countdown interval */public timecount (long millisinfuture, long Countdowninterval) {Super (millisinfuture, countdowninterval);} @Overridepublic void OnTick (Long millisuntilfinished) {mtimebutton.setenabled (false); Mtimebutton.settext ( millisuntilfinished/1000 + "Seconds");} @Overridepublic void OnFinish () {//timed end mtimebutton.setenabled (true); Mtimebutton.settext ("Regain");}}

3. Running the example:




Thank you, my favorite friends pay attention to me!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Combat Simple Tutorial-41st gun (show Countdown button-for obtaining verification code)

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.