设置对话框的研究进展研究进展、对话框

2023-09-08 08:30:34 作者:阳光快乐小男神

我有一个异步任务,不增加的百分比,而它会通过任务。它总是停留在0%0/100

I have a Async Task that does not add the percentage while it is going through the task. It always stays at 0% 0/100

下面是我的code

     private class getAppInfo extends AsyncTask<String, String, String> {
    /** The system calls this to perform work in a worker thread and
      * delivers it the parameters given to AsyncTask.execute() */
    ProgressDialog dialog;

    @Override
    protected void onPreExecute() {
        if(showLoading == true){
             dialog = new ProgressDialog(SelfHelp.this);
             dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
             dialog.setMessage("Loading");
             dialog.setIndeterminate(true);
             dialog.setCancelable(false);   
             dialog.setMax(100);
             dialog.setProgress(100);
             dialog.show();
        }
    }

    @Override
    protected String doInBackground(String... urls) {                       
        String xml = null;
        int count = 0;
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(urls[0]);

            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            xml = EntityUtils.toString(httpEntity);

            while(count != 100){
                publishProgress(""+count);
                count += 5;
            }

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }                                

        Document doc = parser.GetDomElement(xml);
        NodeList nl = doc.getElementsByTagName("topic");
        getChildElements(nl);                           
        return xml;
    }


    @Override
    protected void onProgressUpdate(String... progress) {
        Log.v("count",progress[0]);
        dialog.setProgress(Integer.parseInt(progress[0]));
   }

    /** The system calls this to perform work in the UI thread and delivers
      * the result from doInBackground() */
    @Override
    protected void onPostExecute(String result) {    
        //dialog.setProgress(100);
        menuList.setAdapter(setListItems(menuItems));
        menuList.setTextFilterEnabled(true);
        if(showLoading == true){
            dialog.dismiss();
            showLoading = false;
        }
    }

它进入 onProgressUpdate 和值将变为5,但进度条不会改变。我怎样才能把它递增5,正确显示进度?

It does go into onProgressUpdate and the count goes up by 5 but the progress bar does not change. How can I have it increment by 5 and show the progress properly?

推荐答案

您的问题涉及到 setIndeterminate(真):您应该将其设置为假,如果你想拥有最新进展。如果您 setIndeterminate(真)则ProgressDialog将作为Windows经典沙漏

Your issue is related to setIndeterminate(true): You should set it to false if you want to have progress update. if you setIndeterminate(true) then the ProgressDialog will work as the classic Windows Hourglass

 
精彩推荐
图片推荐