android – 设置对话框的进度

我有一个异步任务,它不会在通过任务时添加百分比.它始终保持在0%0/100

这是我的代码

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并正确显示进度?

解决方法

您的问题与setIndeterminate(true)有关:如果要进行更新,应将其设置为false.如果setIndeterminate(true),则ProgressDialog将作为经典的Windows沙漏工作

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...