任务下载进度表总结
完整的代码再最下面
1.程序图片
2.程序分析
2.1 activity_main.xml源码
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始下载"
android:id="@+id/down"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/stop"
android:text="暂停下载"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="继续下载"
android:id="@+id/jixu"
android:layout_weight="1"/>
</LinearLayout>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressbar"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:gravity="center"
/>
2.2 Download 类继承AsyncTask<,,>
class Download extends AsyncTask<Integer,Integer,String>{
private ProgressBar progressBar;
private TextView textmsg;
@Override
protected String doInBackground(Integer... integers) {
for(;i<integers[0];i++)
{
if(isCancelled()) break;
publishProgress<