ProgressDialog in AsyncTask

后端 未结 7 2338
一个人的身影
一个人的身影 2020-11-22 07:54

I\'m trying to display a custom progressdialog while loading RSS feed from an HTTP server, I made a hard search, but nothing helped me to do this, the only thing I know is t

7条回答
  •  春和景丽
    2020-11-22 08:40

    AsyncTask is very helpful!

    class QueryBibleDetail extends AsyncTask{
            private Activity activity;
            private ProgressDialog dialog;
            private Context context;
    
            public QueryBibleDetail(Activity activity){
                this.activity = activity;
                this.context = activity;
                this.dialog = new ProgressDialog(activity);
                this.dialog.setTitle("查询经文");
                this.dialog.setMessage("正在查询:"+tome+chapterID+":"+sectionFromID+"-"+sectionToID);
                if(!this.dialog.isShowing()){
                    this.dialog.show();
                }
            }
    
            @Override
            protected String doInBackground(Integer... params) {
                Log.d(TAG,"经文doInBackground");
                publishProgress(params[0]);
    
                if(sectionFromID > sectionToID){
                    return "";
                }
    
                String queryBible = "action=query_bible&article="+chapterID+"&id="+tomeID+"&verse_start="+sectionFromID+"&verse_stop="+sectionToID+"";
                try{
                    String bible = (Json.getRequest(HOST+queryBible)).trim();
                    bible = android.text.Html.fromHtml(bible).toString();
                    return bible;
                }catch(Exception e){
                    e.printStackTrace();
                }
                return null;
            }
    
            @Override
            protected void onPostExecute(String bible){
                Log.d(TAG,"经文onPostExecute");
                TextView bibleBox = (TextView) findViewById(R.id.bibleBox);
                bibleBox.setText(bible);
                this.dialog.dismiss();
            }
        }
    

提交回复
热议问题