在android开发中,我们常常需要用到计时器,倒计时多少秒后再执行相应的功能,下面我就分别来讲讲这三种常用的计时的方法. 一.CountDownTimer 该类是个抽象类,如果要使用这个类中的方法,就必须继承这个类实现它内部的抽象方法,该继承的类中通常是存在某个类的内部类中.该类主要功能就是可以我们自己设置倒计时的秒数和时间间隔,且只有一个构造方法,构造函数为: public CountDownTimer(long millisInFuture, long countDownInterval)…
public static void scrollToListviewTop(final XListView listView) { listView.smoothScrollToPosition(0); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (listView.getFirstVisiblePosition() >…
自从你进入程序员的世界,就开始照着书本编写着各种helloworld,大笔一挥: printf("Hello World!\n"); 于是控制台神奇地出现了一行字符串,计算机一句温馨的问候将多少年轻的骚年们引入了这个比58同城还神奇的世界...... 今天的旅行从这里开始: #include <stdio.h> int main(){ float a = 0.5; printf("float a is %f\n",a); return 0;} 第一步:进…
前言 做过 Android 开发的童鞋都知道,不能在非主线程修改 UI 控件,因为 Android 规定只能在主线程中访问 UI ,如果在子线程中访问 UI ,那么程序就会抛出异常 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy . 并且,Android 也不建议在 UI 线程既主线程中做一些耗时操作,否则会导致程序 A…
ι 版权声明:本文为博主原创文章,未经博主允许不得转载. 先看Handler的定义: /** * A Handler allows you to send and process {@link Message} and Runnable * objects associated with a thread's {@link MessageQueue}. Each Handler * instance is associated with a single thread and that thre…