【问题标题】:Android AsyncTask Progress bar [duplicate]Android AsyncTask 进度条 [重复]
【发布时间】:2012-02-06 08:43:32
【问题描述】:

可能重复:
Progressbar togther with asyncTask

我在一个项目中有一个可扩展列表视图。如果有人单击该组,则必须加载数据,并且加载时间必须出现进度条。我想通过异步任务来完成。请给我示例代码。 提前致谢。

【问题讨论】:

    标签: android android-asynctask


    【解决方案1】:

    请试试这个

    public class LoadData extends AsyncTask<Void, Void, Void> {
        ProgressDialog progressDialog;
        //declare other objects as per your need
        @Override
        protected void onPreExecute()
        {
            progressDialog= ProgressDialog.show(YourActivity.this, "Progress Dialog Title Text","Process Description Text", true);
    
            //do initialization of required objects objects here                
        };      
        @Override
        protected Void doInBackground(Void... params)
        {   
    
             //do loading operation here  
            return null;
        }       
        @Override
        protected void onPostExecute(Void result)
        {
            super.onPostExecute(result);
            progressDialog.dismiss();
        };
     }
    

    你可以调用它

    LoadData task = new LoadData();
    task.execute();
    

    【讨论】:

    • 他想要加载时间......哎呀......!
    • 我们如何才能在我们调用的方法中获得任务已经完成??
    • 完成Async Task后要做的任务可以放在onPostExecute
    • 如何让其他线程等到Asnyc任务的值来了??
    • @abhishekameta,有一个 get() 方法。在此示例中,它将如下所示:task.get()
    猜你喜欢
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    • 2019-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    相关资源
    最近更新 更多