gpt4 book ai didi

android - 如何在获得服务器响应后停止进度条

转载 作者:行者123 更新时间:2023-11-29 15:34:11 25 4
gpt4 key购买 nike

我试图在收到服务器响应后停止进度条。下面是我用过的xml代码

activity.xml

  <ProgressBar
android:layout_weight="1"
android:id="@+id/progressBar"
android:indeterminate="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:minWidth="40dp"
tools:ignore="MissingConstraints" />

activity.kt

 var progressBar =  findViewById(R.id.progressBar) as ProgressBar
doAsync {
try {
progressBar.setVisibility(View.VISIBLE);
appList = getAppList(requestBody, LAUNCHER_BASE_URL)
Log.d("App list =", appList.toString())
appInfoList = populateList()
progressBar.setVisibility(View.GONE);
} catch (e: Exception) {
progressBar.setVisibility(View.GONE);
Log.e("Exception-launcher", e.toString())
}

从上面的代码来看,即使得到响应,进度条也不会停止。任何帮助将不胜感激

我试过了,但是进度条停止后页面变成空白

最佳答案

在您的 try 子句中也添加 progressBar.setVisibility(View.INVISIBLE);,因为在当前状态下,它只会移除 API 失败时的加载:

 var progressBar =  findViewById(R.id.progressBar) as ProgressBar
doAsync {
try {
progressBar.setVisibility(View.VISIBLE);
appList = getAppList(requestBody, LAUNCHER_BASE_URL)
Log.d("App list =", appList.toString())
appInfoList = populateList()
progressBar.setVisibility(View.INVISIBLE);
} catch (e: Exception) {
progressBar.setVisibility(View.INVISIBLE);
Log.e("Exception-launcher", e.toString())
}

关于android - 如何在获得服务器响应后停止进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55488938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com