亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

加載器在調用 web api Android 時不顯示

加載器在調用 web api Android 時不顯示

C#
慕雪6442864 2022-12-31 10:33:08
我有以下加載程序 xml -custom_progress_dialog.xml(布局)<?xml version="1.0" encoding="utf-8" ?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/progres"    android:layout_width="100dp"    android:layout_height="100dp"    android:layout_gravity="center"    android:layout_centerVertical="true"    android:layout_centerHorizontal="true"    android:background="#000000" >  <ProgressBar      android:indeterminate="true"      style="?android:attr/progressBarStyleLarge"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:layout_margin="20dp"      android:layout_centerInParent="true"      android:indeterminateDrawable="@drawable/custom_progress_bar" /></RelativeLayout>custom_progress_bar.xml(可繪制)<?xml version="1.0" encoding="utf-8" ?><rotate xmlns:android="http://schemas.android.com/apk/res/android"    android:pivotX="50%"    android:pivotY="50%"    android:fromDegrees="0"    android:toDegrees="360">  <shape android:shape="ring" android:innerRadiusRatio="3"      android:thicknessRatio="8" android:useLevel="false">    <size        android:width="76dip"        android:height="76dip" />    <gradient        android:type="sweep"        android:useLevel="false"        android:startColor="@android:color/transparent"        android:endColor="#00FF00"        android:angle="0" />  </shape></rotate>然后有一個ShowLoading方法 -public static Dialog ShowLoading(Context context){    Dialog dialog = new Dialog(context, Android.Resource.Style.ThemeTranslucentNoTitleBar);    dialog.SetContentView(Resource.Layout.custom_progress_dialog);    dialog.Window.SetGravity(GravityFlags.Center);    dialog.SetCancelable(true);    dialog.CancelEvent += delegate { dialog.Dismiss(); };    dialog.Show();    return dialog;}我遇到的問題是,當我調用 Web 服務時,它沒有顯示進度條,并且應用程序基本上凍結,直到對 Web API 的調用完成。我什至從方法中刪除了 web api 調用,以測試進度條在調用時是否正確顯示。如何在 api 調用進行時顯示進度條?
查看完整描述

1 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

不要在主線程調用api,使用AsyncTask調用api



public class MyAsync extends AsyncTask<Void, Void, Void> {


    @Override

        protected void onPreExecute() {

            super.onPreExecute();

           //show progress dialog here

        }


        @Override

        protected Void doInBackground(Void... voids) {

            //call api here

            return null;

        }


        @Override

        protected void onPostExecute(Void aVoid) {

            super.onPostExecute(aVoid);

            //hide progress dialog here

        }

    }

執行它使用這個


new MyAsync().execute();


查看完整回答
反對 回復 2022-12-31
  • 1 回答
  • 0 關注
  • 72 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號