【问题标题】:How to download file one by one in a ListView?如何在 ListView 中逐个下载文件?
【发布时间】:2018-06-03 15:59:25
【问题描述】:

我有来自https://awsrh.blogspot.com/2018/05/volley-glide-tutorial-send-data-and.html的源代码

我要下载pdf文件,从服务器上一个一个按钮点击一下

例子

【问题讨论】:

    标签: java android


    【解决方案1】:

    所以首先你需要一个普通的 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
        }
    }

    【讨论】:

    • public void downloadFile() { //这里放你下载的东西 //所以从你的服务器下载文件 }
    • 我不知道怎么做嘿嘿:D
    • 试试把你的链接放到下载文件() {这里}
    • 先制作布局文件,制作jar文件
    • 浏览这个link
    【解决方案2】:

    这里是下载进度的 SO 线程:Download a file with Android, and showing the progress in a ProgressDialog
    这是另一个通过 android 的下载管理器下载的 SO 线程:Download Files Using download manager


    你现在只需要 for 循环 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      • 2017-09-21
      • 2012-11-18
      • 2014-07-05
      • 2019-01-17
      相关资源
      最近更新 更多