1 效果图
2 实现说明
实现流程
Step One 弹出进度条对话框
Step Two 执行线程,在线程中实现数据的异步加载
Step Three 在线程数据加载完成后,调用Handler并集合数据,更新界面
3源码
//添加异步操作 m_Dialog=ProgressDialog.show(m_context, "请等待...", "正在下载安装文件,请稍后...",true); //mRegsiterHandler.sleep(100); new Thread(new Runnable(){ @Override publicvoid run() { //加载数据 result=0; try{ //下载文件 String url="http://00.00.00.00:80/nationaltest.html"; HttpClient client =new DefaultHttpClient(); HttpGet get =new HttpGet(url); HttpResponse response; response = client.execute(get); HttpEntity entity = response.getEntity(); long length = entity.getContentLength(); InputStream is = entity.getContent(); FileOutputStream fileOutputStream =null; if (is !=null) { File file =new File(Environment.getExternalStorageDirectory(), "nationaltest.apk"); fileOutputStream =new FileOutputStream(file); byte[] buf =newbyte[1024]; int ch =-1; while ((ch = is.read(buf)) !=-1) { fileOutputStream.write(buf, 0, ch); } } fileOutputStream.flush(); if (fileOutputStream !=null) { fileOutputStream.close(); } result=2; } catch(Exception ex){ result=-1; } //更新界面 // Update the progress bar mHandler.post(new Runnable() { publicvoid run() { if(result==2) install(); else Toast.makeText(m_context, "下载文件失败,请检查网络连接", Toast.LENGTH_SHORT).show(); } }); m_Dialog.dismiss(); }}).start(); }
相关推荐
android 自定义组合progressdialog进度条,方便你的使用............................................................................................
Android ProgressDialog 进度条对话框的模拟实现和代码解析,此为例子源代码,在本例中实现进度条需要调用onPrepareDialog()方法和showDialog(),应用程序处理进度条指示功能。
Android ProgressDialog进度条对话框
android网络加载显示进度条 ProgressDialog+Thread应用
该项目通过使用两种不同的方法来实现了 ProgressDialog 的功能,又在项目中集成了自定义的 LoadingDialog 供大家选择,赶快下载起来吧。 为了让大家方便下载,所以只需要一个积分就可以了,要是大家觉得积分还是有点...
实现文件的复制 及 进度条的显示 progressdialog
Android中自定义ProgressDialog实现加载滚动条效果,例如显示“请稍后……”,希望对于有帮助
android dialog ——ProgressDialog 进度条对话框详解
Android百分比加载进度条的实例,又一个使用ProgressDialog创建进度条的例子,进度条的实例方法,其实比较简单,先看以下代码: 重写onCreateDialog方法 switch(id){//对id进行判断 case PROGRESS_DIALOG://...
主要介绍了Android ProgressDialog用法之实现app上传文件进度条转圈效果,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
android 自定义ProgressDialog对话框,
android自定义ProgressDialog样式详解,一分钟教会你如何自定义android样式。
NULL 博文链接:https://android-zhang.iteye.com/blog/1611319
android 自定义progressDialog实现 加载转圈等待
android progressDialog各种用法android progressDialog各种用法android progressDialog各种用法android progressDialog各种用法
自定义progressdialog加载动画,这里还有旋转的加载条,美团,多个图片动画
这个demo是关于android中继承Dialog重新自定义一个ProgressDialog。 需求:带加载图片和文字说明,可定时停止也可被动中断。 如有BUG或者不完善,欢迎小伙伴们提出~
Android中自定义ProgressDialog实现加载滚动条效果(例如:1.加载中…2.请稍后……等)
NULL 博文链接:https://duohuoteng.iteye.com/blog/1504193
在程序需要时间执行任务的时候,提示进度条友好的告诉用户说,当前任务还没有完成,请稍稍等待,进度条经常使用在APP下载应用、更新应用、加载网络数据中,使用频繁,常见的进度条有ProgressDialog、ProgressBar,...