没有合适的资源?快使用搜索试试~ 我知道了~
\Android文件下载进度条的实现.txt
4星 · 超过85%的资源 需积分: 10 57 下载量 196 浏览量
2011-06-08
23:03:49
上传
评论 1
收藏 5KB TXT 举报
温馨提示
试读
6页
\Android文件下载进度条的实现.txt\Android文件下载进度条的实现.txt
资源推荐
资源详情
资源评论
近几天因为在写高清壁纸的服务器端(基于PHP+MySql),所以好几天没更新博客了,顺便汇报一下高清壁纸的开发进度:服务器端已经改写,原来是一条数据一条数据加,现在是Flash批量上传图片,自动添加数据(这是后台,大家当然看不到啦)。另外,图片数据都放到自己的虚拟主机上了,所以大家可能觉得这几天下载图片特别慢。原来放POCO,速度比较快,但是毕竟是免费的,不放心,怕哪天被人发现了大流量下载,把我帐号图片删了,到时哭都来不及,而且那样也实现不了上传自动添加数据。新版客户端方面,目前多语言以及HVGA支持都已经完成,现在在做下载进度条(因为服务器稍慢,怕有些性子急的同学等不了)。汇报完毕,开始今天学习。今天的这段代码是网上找的,自己做了些小改,通过模拟器测试。文件下载进度条控制(就是为了高清壁纸加个进度条),自己研究了好久,但是进度条只能显示缓存写入文件的进度,不能显示下载进度。找了好久,终于找到一段用的代码,所以记录下来,大家分享。
布局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/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<ProgressBar android:id="@+id/down_pb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
/>
</LinearLayout>
package com.pocketdigi.download;
import java.io.FileOutputStream;
布局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/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<ProgressBar android:id="@+id/down_pb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
/>
</LinearLayout>
package com.pocketdigi.download;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.client.ClientProtocolException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class main extends Activity {
/** Called when the activity is first created. */
ProgressBar pb;
TextView tv;
int fileSize;
int downLoadFileSize;
String fileEx,fileNa,filename;
private Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{//定义一个Handler,用于处理下载线程与UI间通讯
if (!Thread.currentThread().isInterrupted())
{
switch (msg.what)
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.client.ClientProtocolException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class main extends Activity {
/** Called when the activity is first created. */
ProgressBar pb;
TextView tv;
int fileSize;
int downLoadFileSize;
String fileEx,fileNa,filename;
private Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{//定义一个Handler,用于处理下载线程与UI间通讯
if (!Thread.currentThread().isInterrupted())
{
switch (msg.what)
剩余5页未读,继续阅读
资源评论
- so_big2012-12-21比较全面··很有用·谢谢·
Kevin-K先森
- 粉丝: 302
- 资源: 137
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功