Android控件之-ProgressDialog

对话框中的拖动条

package com.ko8e;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MyActivity extends Activity {
	/** Called when the activity is first created. */
	private Button button1 = null;
	private Button button2 = null;
	private ProgressDialog pDialog = null;
	int count = 0;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		button1 = (Button) findViewById(R.id.button1);
		button2 = (Button) findViewById(R.id.button2);

		button1.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				pDialog = new ProgressDialog(MyActivity.this);
				pDialog.setIcon(R.drawable.img1);
				pDialog.setTitle("提示");
				pDialog.setMessage("这是一个圆形的进度条");
				pDialog.setIndeterminate(false);
				pDialog.setCancelable(true);
				pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
				pDialog.setButton("确定", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						MyActivity.this.finish();
					}
				});
				pDialog.show();
			}
		});

		button2.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				count = 0;
				pDialog = new ProgressDialog(MyActivity.this);
				pDialog.setIcon(R.drawable.img2);
				pDialog.setTitle("提示");
				pDialog.setMessage("这是一个长形进度条");
				pDialog.setIndeterminate(false);
				pDialog.setCancelable(true);
				pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
				pDialog.setMax(100);
				pDialog.show();

				new Thread(new Runnable() {
					public void run() {
						try {
							while (count <= 100) {
								Thread.sleep(100);
								pDialog.setProgress(count++);
							}
							pDialog.cancel();
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				}).start();
			}
		});
	}
}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
	android:id="@+id/textView"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<Button
	android:id="@+id/button1"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="@string/button1"
	/>
<Button
	android:id="@+id/button2"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="@string/button2"
	/>
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值