编程进度犯规出现在ListActivity [英] ProgressBar Programmatically doesnt appear in ListActivity

查看:129
本文介绍了编程进度犯规出现在ListActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AsyncTask的至极取上下文:

I have an AsyncTask wich is taken a context :

public class DownloadDataPromotions extends AsyncTask<Void, Integer, ArrayList<HashMap<String, String>>>
{
    Context context;

    public DownloadDataPromotions(Context context) 
    {
        this.context = context;
    }
    @Override
    protected void onPreExecute() 
    {
        super.onPreExecute();
    }

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground(Void... params)
    {
                ArrayList<HashMap<String, String>> promoList = new ArrayList<HashMap<String, String>>();
        promoList = DownloadingDataFromWebService();
                      ...
                return promoList;
    }

    @Override
    protected void onProgressUpdate(Integer... values) 
    {

        super.onProgressUpdate(values);
    }

    @Override
    protected void onPostExecute(ArrayList<HashMap<String, String>> promoList) 
    {
        super.onPostExecute(promoList);
                 ...
    }
}

然后我打电话到一张ListActivity(与他的背景下),以显示来自该AsyncTask的donwloaded的所有内容到一个列表中。

Then i'm calling it onto a ListActivity(with his context) in order to display all content donwloaded from this AsyncTask into a List.

但现在我想在这AsyncTask的添加装载机进度至极只能确定的是: 显示在上preExecute(),并停止显示在onPostExecute()方法..

But now i want to add in this AsyncTask a Loader ProgressBar wich is only determinate by : displaying on the onPreExecute() and stop displaying in the onPostExecute() methods..

我有这样的成绘制的内容具有自定义绘制,但我想要当的AsyncTask加载它出现和消失时的AsyncTask结束(编程)。

I have this into drawable content with a custom drawable but I want to make it appear when AsyncTask is loading and disappear when AsyncTask finished (programmatically)..

编辑:

这是工作的罚款:

ProgressBar pb = new ProgressBar(TabPromotionsJSONParsingActivity.this);
                LinearLayout ll = (LinearLayout) findViewById(R.id.linearlayoutProgressBar);
                ll.addView(pb);
                pb.setVisibility(View.VISIBLE);

但问题我现在是,当我的AsyncTask完成阻止它.. 我愿做同样的工作在我的DownloadDataPromotions,有人知道如何?

But the problem I have now is to stop it when my Asynctask finishes.. I would like to do the same task into my DownloadDataPromotions, someone knows how ?

推荐答案

添加code创建的进度在上preExecute方法,并添加code将其隐藏在onPostExecute方法。类似下面(code被添加到您的类):

Add the code to create the ProgressBar in the onPreExecute method and add code to hide it in the onPostExecute method. Something like below (code to be added to your class) :

public class DownloadDataPromotions extends AsyncTask<Void, Integer, ArrayList<HashMap<String, String>>>
{
    ProgressBar pb;
        ...
    @Override
    protected void onPreExecute() 
    {
        super.onPreExecute();

        pb = new ProgressBar(context);
        LinearLayout ll = (LinearLayout) context.findViewById(R.id.linearlayoutProgressBar);
        ll.addView(pb);
        pb.setVisibility(View.VISIBLE);

    }
    ...
    @Override
    protected void onPostExecute(ArrayList<HashMap<String, String>> promoList) 
    {
        super.onPostExecute(promoList);
        if (pb!=null) {
            ((LinearLayout)pb.getParent()).removeView(pb);
        }
    }
}

这篇关于编程进度犯规出现在ListActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆