WEB开发网
开发学院手机开发Android 开发 Android SDK 开发之创建对话框 阅读

Android SDK 开发之创建对话框

 2010-03-23 04:24:00 来源:WEB开发网   
核心提示:progressDialog.setMessage("Loading...");progressThread = new ProgressThread(handler);progressThread.start();return progressDialog;default:return null;

progressDialog.setMessage("Loading...");

progressThread = new ProgressThread(handler);

progressThread.start();

return progressDialog;

default:

return null;

}

}

// Define the Handler that receives messages from the thread and update the progress

final Handler handler = new Handler() {

public void handleMessage(Message msg) {

int total = msg.getData().getInt("total");

progressDialog.setProgress(total);

if (total >= 100){

dismissDialog(PROGRESS_DIALOG);

progressThread.setState(ProgressThread.STATE_DONE);

}

}

};

/** Nested class that performs progress calculations (counting) */

private class ProgressThread extends Thread {

Handler mHandler;

final static int STATE_DONE = 0;

final static int STATE_RUNNING = 1;

int mState;

int total;

ProgressThread(Handler h) {

mHandler = h;

}

public void run() {

mState = STATE_RUNNING;

total = 0;

while (mState == STATE_RUNNING) {

try {

Thread.sleep(100);

} catch (InterruptedException e) {

Log.e("ERROR", "Thread Interrupted");

}

Message msg = mHandler.obtainMessage();

Bundle b = new Bundle();

b.putInt("total", total);

msg.setData(b);

mHandler.sendMessage(msg);

total++;

}

}

/* sets the current state for the thread,

* used to stop the thread */

public void setState(int state) {

mState = state;

}

}

}

Creating a Custom Dialog 创建自定义对话框


上一页  2 3 4 5 6 7 8 9  下一页

Tags:Android SDK 开发

编辑录入:coldstar [复制链接] [打 印]
赞助商链接