Android控件之-ProgressDialog_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > Android控件之-ProgressDialog

Android控件之-ProgressDialog

 2010/12/15 8:01:04  ko8e  http://ko8e.javaeye.com  我要评论(0)
  • 摘要:对话框中的拖动条packagecom.ko8e;importandroid.app.Activity;importandroid.app.ProgressDialog;importandroid.content.DialogInterface;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.Button;publicclassMyActivityextendsActivity
  • 标签:android SSD 控件 Android控件

对话框中的拖动条

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>
?
发表评论
用户名: 匿名