2014年2月24日 星期一

Android Dialog 運用筆記




AlertDialog:

        //建立為開啟WIFI視窗
Builder WifiNotEnable_Dialog = new AlertDialog.Builder(this);
WifiNotEnable_Dialog.setTitle("標題");
WifiNotEnable_Dialog.setMessage("內容");
//建立按鈕
DialogInterface.OnClickListener checkButton = new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int cheak) {
// TODO Auto-generated method stub
switch (cheak) {
case -2: //啟用
//TODO
break;
case -1: //取消
//TODO
break;
default:
                                        //TODO
break;
}
}
};
WifiNotEnable_Dialog.setPositiveButton("右邊按鈕", checkButton);
WifiNotEnable_Dialog.setNegativeButton("左邊按鈕", checkButton);
WifiNotEnable_Dialog.show();

ProgressDialog://讀取等待視窗

ProgressDialog waitingDialog;

waitingDialog = ProgressDialog.show(this, "系統","請等待...",true);
new Thread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(5000);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally{
waitingDialog.dismiss();
}
}
}).start();