當前位置:首頁 » 安卓系統 » android下載進度

android下載進度

發布時間: 2022-08-20 04:28:12

⑴ 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進度不動之前可以下載,以前可以,就是最近的事,求知道的大神說下,求解決

退出重啟一下手機。如果不行。下載一個手機迅雷。

熱點內容
如何下載奧特曼高級化3安卓版 發布:2025-05-14 07:47:31 瀏覽:345
qml文件修改後編譯未生效 發布:2025-05-14 07:31:00 瀏覽:331
內到內演算法 發布:2025-05-14 07:29:11 瀏覽:34
文件夾名字不顯示 發布:2025-05-14 07:27:47 瀏覽:774
oracle的資料庫驅動jar 發布:2025-05-14 07:23:20 瀏覽:556
我的世界電腦版伺服器手機版能進嗎 發布:2025-05-14 07:22:01 瀏覽:679
達內培訓php多少錢 發布:2025-05-14 07:19:10 瀏覽:27
python位元組轉字元串 發布:2025-05-14 07:06:35 瀏覽:422
subplotpython 發布:2025-05-14 06:53:51 瀏覽:662
豎屏大屏導航工廠密碼一般是多少 發布:2025-05-14 06:49:29 瀏覽:806