解决方案 »
- 关于蓝牙socket 服务器端首次accept总出错!
- 坐等大神讲解android opengl 绘图透明度的问题。
- 读取通话记录,实现ListView的优化,并且是源码级的开发.很给力~
- android 录制声音 播放有噪音?
- ArrayAdapter的问题,我传进来一个20位的数组 但是显示出来就是40位 很邪门 内有代码 显示的是传进来数组位数的2倍
- 这个动画怎么做?
- android APK开发中如何取得当前系统时间?
- android 上的xml parser
- 现在要做一个android分屏异显,没有思路,求指点
- 写一个工具类保存手机地址address为xml的时候 报空指针异常.第90行出现空指针异常。adress明明有输出啊?
- android中如何如何让dailog横屏显示
- MyEclipse安装ADT
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)findViewById(R.id.picture);
button=(Button)findViewById(R.id.button);
dialog=new ProgressDialog(this);
dialog.setTitle("提示");
dialog.setMessage("图片下载中");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setCancelable(false);
}
public class myTask extends AsyncTask<String,Integer,Bitmap>{
//表示任务操作之前的操作
@Override
protected void onPreExecute(){
super.onPreExecute();
dialog.show();
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
dialog.setProgress(values[0]);
}
//主要执行耗时操作
@Override
protected Bitmap doInBackground(String... params) {
// TODO Auto-generated method stub
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
InputStream inputStream=null;
Bitmap bitmap=null;
try {
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(params[0]);
HttpResponse httpResponse=httpClient.execute(httpGet);
if(httpResponse.getStatusLine().getStatusCode()==200){
inputStream=httpResponse.getEntity().getContent();
long file_length=httpResponse.getEntity().getContentLength();
int len=0;
byte[] data=new byte[1024];
int total_length=0;
while((len=inputStream.read(data))!=-1){
total_length+=len;
int value=(int)((total_length/(float)file_length)*100);
publishProgress(value);
outputStream.write(data,0,len);
}
byte[]result=outputStream.toByteArray();
bitmap=BitmapFactory.decodeByteArray(result, 0, result.length);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
if(inputStream!=null){
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return bitmap;
}
//跟新UI界面
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
imageView.setImageBitmap(result);
dialog.dismiss();
}
}
我这个是横向的,你可以选择圆形的,而且我这个可以根据网络下载的,显示进度。你可以根据自己的需要改一下,把你的计算操作放到doInBackground里面就可以了。