android下载进度
⑴ android studio 一打开项目下方就又有个下载进度条,每次打开都要下载,怎么回事啊
如果是第一次导入的项目,她会去网络仓库下载你build.gride里导入的包比如http请求的,或者第三方组件的包。会有各种类似下载的进度条。之后打开都是检查版本什么的,还有初始化项目,也会耗费一定的时间
⑵ android中如何获取listview中其中一个Item中的进度条对象来更新下载进度
public class MainActivity extends Activity
{
private ListView listView;
private DownloadAdapter adapter;
private List<String> lists = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (int i = 0; i < 10; i++)
{
lists.add("button" + i);
}
listView = (ListView) findViewById(R.id.listView1);
adapter = new DownloadAdapter(this, lists);
listView.setAdapter(adapter);
}
}
public class DownloadAdapter extends BaseAdapter
{
private Context context;
private List<String> list;
private LayoutInflater inflater;
public DownloadAdapter(Context context, List<String> list)
{
this.context = context;
this.list = list;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount()
{
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position)
{
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position)
{
// TODO Auto-generated method stub
return list.get(position).hashCode();
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
MyHolder myHolder = null;
if (convertView == null)
{
convertView = inflater.inflate(R.layout.item, null);
myHolder = new MyHolder();
myHolder.bar = (ProgressBar) convertView
.findViewById(R.id.progressBar1);
myHolder.button = (Button) convertView.findViewById(R.id.button1);
convertView.setTag(myHolder);
}
else
{
myHolder = (MyHolder) convertView.getTag();
}
myHolder.button.setText(list.get(position));
MyDownLoadThread down = new MyDownLoadThread(myHolder.bar,
myHolder.button);
myHolder.button.setOnClickListener(down);
return convertView;
}
class MyHolder
{
private ProgressBar bar;
private Button button;
}
public class MyDownLoadThread extends Thread implements OnClickListener
{
private ProgressBar pBar;
private Button btn;
private int index = 0;
private boolean isStart = false;
private Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
pBar.setProgress(index);
}
};
public MyDownLoadThread(ProgressBar pBar, Button btn)
{
this.pBar = pBar;
this.btn = btn;
}
@Override
public void onClick(View v)
{
if (!isStart)
{
isStart = true;
btn.setText("开始下载");
pBar.setMax(100);
this.start();
}
}
@Override
public void run()
{
while (index <= 100)
{
index++;
handler.sendEmptyMessage(0);
try
{
sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if (index > 100)
{
btn.setText("下载完成");
break;
}
}
}
}
}
简单的demo 仅供参考,希望对你有用
⑶ 安卓开发时,下载文件时进度条线程阻塞问题(具体如下)
自己debug看一下,在循环最后sleep一下
⑷ android通知栏中的下载进度条范例
直接放子线程里 然后handler接然后加入进度条 在每次接的数据上显示出来进度
⑸ Android 下载进度条问题。
conn.setConnectTimeout(5000);
// 获取到文件的大小
pd.setMax(conn.getContentLength());
// 获取当前下载量
pd.setProgress(total);
把pd.setProgress(total);写在while语句里循环更新就OK
⑹ 为什么在android市场下载不了软件,进度总是0%
主要是网络原因。如果你是用wlan,没有限制;如果你是用蜂窝网,看看设置里有个仅wlan下载。
⑺ 谁知道怎样在安卓手机通知栏里显示下载进度条啊
通知栏显示所用到的布局文件content_view.xml
主运行类:
packageyyy.testandroid4;
importjava.util.Timer;
importjava.util.TimerTask;
importandroid.app.Activity;
importandroid.app.AlertDialog.Builder;
importandroid.app.Notification;
importandroid.app.NotificationManager;
importandroid.app.PendingIntent;
importandroid.content.DialogInterface;
importandroid.content.Intent;
importandroid.content.pm.PackageManager.NameNotFoundException;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.RemoteViews;
importandroid.widget.Toast;
{
privateHandlerhandler=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
//TODOAuto-generatedmethodstub
super.handleMessage(msg);
switch(msg.what){
case0:
notif.contentView.setTextViewText(R.id.content_view_text1,len+"%");
notif.contentView.setProgressBar(R.id.content_view_progress,100,len,false);
manager.notify(0,notif);
break;
case1:
Toast.makeText(TestAndroid4Activity.this,"下载完成",0).show();
break;
default:
break;
}
}
};
privateButtonupdate,cancel;
privateintlocalVersion,serverVersion;
privateintlen;
;
privateNotificationnotif;
/**.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
update=(Button)findViewById(R.id.update);
update.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
//点击通知栏后打开的activity
Intentintent=newIntent(TestAndroid4Activity.this,OtherActivity.class);
PendingIntentpIntent=PendingIntent.getActivity(TestAndroid4Activity.this,0,intent,0);
manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notif=newNotification();
notif.icon=R.drawable.logo;
notif.tickerText="新通知";
//通知栏显示所用到的布局文件
notif.contentView=newRemoteViews(getPackageName(),R.layout.content_view);
notif.contentIntent=pIntent;
manager.notify(0,notif);
newDownLoadThread().start();
}
});
}
}
{
privateTimertimer=newTimer();
@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
super.run();
timer.schele(newTimerTask(){
@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
Messagemsg=newMessage();
msg.what=0;
msg.obj=len;
handler.sendMessage(msg);
if(len==100){
timer.cancel();
handler.sendEmptyMessage(1);
}
}
},0,1000);
len=0;
try{
while(len<100){
len++;
Thread.sleep(1000);
}
}catch(InterruptedExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
}
⑻ android gridview 的每个item都有一个下载进度条,当activity翻页再返回来,进度条就没有进度显示了
用一个map记录一下 用position做key 然后每次get view的时候设置一下 进度条的值
⑼ android下载界面进度条接续及更新问题
用handler更新ui, 也就是多线程
⑽ 安卓手机下载APP进度不动之前可以下载,以前可以,就是最近的事,求知道的大神说下,求解决
退出重启一下手机。如果不行。下载一个手机迅雷。