【发布时间】:2018-03-14 14:19:10
【问题描述】:
我想上传一个带有进度条的文件,该文件有一个显示进度百分比的进度条,我想通过 post 方法发送一些参数 我该怎么做?
【问题讨论】:
标签: android upload progress-bar retrofit
我想上传一个带有进度条的文件,该文件有一个显示进度百分比的进度条,我想通过 post 方法发送一些参数 我该怎么做?
【问题讨论】:
标签: android upload progress-bar retrofit
如果您使用的是 Retrofit 2,也许您会发现这个答案很有帮助 Is it possible to show progress bar when upload image via Retrofit 2
【讨论】:
first of yore java file in upload pic call in ....progress bar initiation...
-----------------------------------------------------
SignUp.this.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
Call<UploadPhoto> call = apiService.uploadFile(fileToUpload, filename, api, user_email);
call.enqueue(new Callback<UploadPhoto>() {
@Override
public void onResponse(Call<UploadPhoto> call, Response<UploadPhoto> response) {
SignUp.this.findViewById(R.id.progress_bar).setVisibility(View.GONE);
UploadPhoto inquiryResponse = response.body();
if (inquiryResponse.getStatus().equals("1")) {
} else {
}
}
@Override
public void onFailure(Call<UploadPhoto> call, Throwable t) {
}
});
-----------------------------------------------------------
and then creat xml file : >> progress_uploading_layout.xml
--------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone"
android:background="@android:color/transparent"
android:orientation="vertical">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/uploading"
android:textColor="@color/green"
android:textSize="20sp" />
</LinearLayout>
-----------------mention your activity----
as put your activity_main as xml file ..
<include layout="@layout/progress_uploading_layout"/>
【讨论】: