package com.example.accessdatabase;
import org.xutils.x;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
@ContentView(R.layout.activity_button)
public class buttonActivity extends Activity {
private ArrayAdapter<String> adapter;
private String[] data;
@ViewInject(R.id.button_login)
private Button button_login;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
x.view().inject(this);
button_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
button_login.setEnabled(false);
button_login.setText("正在登陆中");
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.v("", "登陆按钮");
handler.sendEmptyMessage(2);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.v("", "登陆按钮");
handler.sendEmptyMessage(3);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.v("", "登陆按钮");
new Thread(new Runnable() {
@Override
public void run() {
for(int i=3;i>0;i--){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.v("", "我是线程2");
Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putInt("count", i);
msg.setData(bundle);
msg.what = 6;
handler.sendMessage(msg);
}
handler.sendEmptyMessage(1);
}
}).start();
}
}).start();
// new Handler().postDelayed(new Runnable() {
// public void run() {
// button_login.setText("登陆成功");
// }
// }, 10000);
// new Handler().postDelayed(new Runnable() {
// public void run() {
// button_login.setText("正在下载用户资料");
// }
// }, 11000);
// new Handler().postDelayed(new Runnable() {
// public void run() {
// button_login.setText("下载成功");
// }
// }, 21000);
// new Handler().postDelayed(new Runnable() {
// public void run() {
// button_login.setText("准备进入系统倒计时3");
// }
// }, 22000);
// new Handler().postDelayed(new Runnable() {
// public void run() {
// button_login.setText("准备进入系统倒计时2");
// }
// }, 23000);
// new Handler().postDelayed(new Runnable() {
// public void run() {
// button_login.setText("准备进入系统倒计时1");
// }
// }, 24000);
// new Handler().postDelayed(new Runnable() {
// public void run() {
// Intent intent = new Intent();
// intent.setClass(buttonActivity.this, success.class);
// startActivity(intent);
// }
// }, 25000);
}
});
}
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
if (msg.what == 6) {
button_login.setText(msg.getData().getInt("count")+"");
}
if (msg.what == 5) {
button_login.setText("3秒后进入系统");
}
if (msg.what == 4) {
button_login.setText("资料下载成功");
}
if (msg.what == 3) {
button_login.setText("正在下载用户资料");
}
if (msg.what == 2) {
button_login.setText("登陆成功");
}
if (msg.what == 1) {
Intent intent = new Intent();
intent.setClass(buttonActivity.this, success.class);
startActivity(intent);
}
}
};
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登陆按钮" />
</LinearLayout>