用户
 找回密码
 注册会员
搜索

Android控件-ProgressDialog弹出框

[复制链接]
发表于 2012-4-22 22:04:04
[XML] 纯文本查看 复制代码
<BUTTON 
android:text="圆形进度条" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<BUTTON 
android:id="@+id/button2" 
android:text="长方形进度条" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">


[Java] 纯文本查看 复制代码
private Button xhButton1, xhButton2;
private int xh_count;
ProgressDialog xh_pDialog;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
xhButton1 = (Button) findViewById(R.id.button1);
xhButton2 = (Button) findViewById(R.id.button2);

xhButton1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
xh_pDialog = new ProgressDialog(TabWidgetActivity.this);
xh_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); // 圆形进度条
xh_pDialog.setTitle("提示");
xh_pDialog.setMessage("这是一条提示信息");
xh_pDialog.setIcon(R.drawable.icon);
xh_pDialog.setIndeterminate(false);
xh_pDialog.setCancelable(false);
xh_pDialog.setButton("确定", new OnDialogClickListener());
xh_pDialog.show();

}
});

xhButton2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
xh_pDialog = new ProgressDialog(TabWidgetActivity.this);
xh_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// 长方形进度条
xh_pDialog.setTitle("提示");
xh_pDialog.setMessage("这是一条提示消息");
xh_pDialog.setIcon(R.drawable.icon);
xh_pDialog.setCancelable(false);
xh_pDialog.setProgress(100);
xh_pDialog.setButton("确定", new OnDialogClickListener());
xh_pDialog.show();

new Thread() {
public void run() {
xh_count = 0;
try {
while (xh_count <= 100) {
xh_pDialog.setProgress(xh_count++);
Thread.sleep(100);
}
xh_pDialog.cancel();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
xh_pDialog.cancel();
}
}
}.start();
}
});

}

class OnDialogClickListener implements DialogInterface.OnClickListener {

@Override
public void onClick(DialogInterface dialog, int arg1) {
// TODO Auto-generated method stub
dialog.cancel();
}

}
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

返回顶部