package org.lxh.demo;import android.app.Activity;import android.app.ProgressDialog;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MyDialogDemo extends Activity {private Button mybut = null ;// 定义按钮private static final int MAX_PROGRESS = 100 ;// 最大值@Override public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);super.setContentView(R.layout.main); // 调用布局管理器this.mybut = (Button) super.findViewById(R.id.mybut) ;// 取得按钮this.mybut.setOnClickListener(new OnClickListenerImpl()) ;// 设置事件类}private class OnClickListenerImpl implements OnClickListener { @Overridepublic void onClick(View view) {final ProgressDialog proDia = new ProgressDialog(MyDialogDemo.this) ;proDia.setTitle("搜索网络") ;proDia.setMessage("请耐心等待") ;proDia.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) ;// 水平进度条proDia.setMax(MAX_PROGRESS) ;// 设置进度的最大值proDia.setProgress(30) ;// 从进度30开始proDia.setButton("后台处理", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {proDia.dismiss() ;// 关闭对话框}}) ;proDia.setButton2("详细信息", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {}}) ;proDia.onStart() ;// 启动进度new Thread(){public void run(){// 线程的主体类for (int x = 0; x < MAX_PROGRESS; x++) {try {Thread.sleep(500); // 运行三秒} catch (Exception e) {} proDia.incrementProgressBy(10) ;}proDia.dismiss() ;}}.start() ;proDia.show() ;// 显示对话框}}}


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"><Button android:id="@+id/mybut"android:text="查找网络" android:layout_width="wrap_content" android:layout_height="wrap_content"/></LinearLayout> 

更多相关文章

  1. Android(安卓)为Notification加上一个进度条
  2. ch07 Android(安卓)日期与时间对话框
  3. Android(安卓)弧形进度条
  4. 安装包更新
  5. Android(安卓)studio中音频播放与进度条联动
  6. ch07 Android(安卓)日期与时间对话框
  7. android定制对话框
  8. 不让屏幕翻转扰乱你的进度对话框
  9. 从零开始--系统深入学习android(实践-让我们开始写代码-Android框

随机推荐

  1. android 制作输入法
  2. Android Studio使用总结
  3. android 应用在启动后进行全局的的初始化
  4. Android实现签名涂鸦手写板
  5. android webview 设置
  6. AndroidStudio打包apk出现的问题 `Error:
  7. react-native开发实例之替换默认logo——
  8. textview scroll
  9. Android Studio如何引用外部Library工程
  10. Android开发(一)拨打电话程序