ProgressDialog 一个使用类,多多提建议

贴上代码

public class MyProgressDialog {

public static ProgressDialog pd;
public static Handler handler;
public Context mContext;

// 启动 进度条
public static void startProgressDialog() {
new Thread() {
public void run() {
try {
handler.sendEmptyMessage(0);
} catch (Exception e) {
// TODO: handle exception
}

}
}.start();
}

// 显示 或者 取消

public static void handlerProgressDialog(Context mContext) {
try {
pd = new ProgressDialog(mContext);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setMessage("数据加载中...");
handler = new Handler() {
public void handleMessage(Message msg) {//
if (!Thread.currentThread().isInterrupted()) {
switch (msg.what) {
case 0:
try {
pd.show();//
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
break;
case 1:
pd.hide();//
break;
}
}
super.handleMessage(msg);
}
};
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

}

}

如何使用

 

//  激活 进度条

MyProgressDialog.handlerProgressDialog(Context);

// 开启
MyProgressDialog.startProgressDialog();

// 消失
MyProgressDialog.handler.sendEmptyMessage(1);

// 销毁
MyProgressDialog.pd.dismiss();

 

大家看看好用不  多多提建议

posted on 2012-11-09 15:09  puppte_bear  阅读(187)  评论(0)    收藏  举报

导航