【发布时间】:2018-06-03 15:59:25
【问题描述】:
我有来自https://awsrh.blogspot.com/2018/05/volley-glide-tutorial-send-data-and.html的源代码
我要下载pdf文件,从服务器上一个一个按钮点击一下
例子
【问题讨论】:
我有来自https://awsrh.blogspot.com/2018/05/volley-glide-tutorial-send-data-and.html的源代码
我要下载pdf文件,从服务器上一个一个按钮点击一下
例子
【问题讨论】:
所以首先你需要一个普通的 Button[在 yourlayoutfile.yml 中执行此操作]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_test"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="198dp"
android:text="Download" />
</RelativeLayout>
现在在你的 Activity 中的 Button 上设置一个 OnClickListener:
public class MainActivity extends AppCompatActivity {
private Button downloadButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
downloadButton= (Button) findViewById(R.id.button);
downloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
downloadFile();
}
});
}
public void downloadFile() {
//Here put-in youre download stuff
//so download the file from your server
}
}
【讨论】:
这里是下载进度的 SO 线程:Download a file with Android, and showing the progress in a ProgressDialog
这是另一个通过 android 的下载管理器下载的 SO 线程:Download Files Using download manager
你现在只需要 for 循环 :)
【讨论】: