简体   繁体   中英

Starting AsyncTask in the onPostExecute

So here is how it is :

I have an AsyncTask with a TimerTask. Every 15 seconds the AsyncTask is run. The AsyncTask gets XML data and put those in dynamically created TextView contained in dynamically create TableRow.

onPostExecute i create all my tableRow and TextView and then in order to not have them double instead of refresh i remove the tableRow views.

protected void onPostExecute(Document result)
{
if(TableLayout.getChildAt(1) == null)
{
    //All my code to show tableRow and TextView
else
{
    int u = 20;
    while(tl.getChildAt(1) != null)
    {
        if(tl.getChildAt(u) != null)
            tl.removeViewAt(u);
        u--;
    }
}

So yeah everything works just fine. I just want to know if there is some way to ask my TimerTask to restart right away instead of waiting x millis sec for timerTask so start again?

Thanks for your help!

So yeah i found out a way to do this. I'll post in case someone else wants to do something like that.

protected void onPostExecute(Document result)
    {

        if(tl.getChildAt(1) == null)
        {
            //do some code              
        }
        else
        {
            int u = 20;
            while(tl.getChildAt(1) != null)
            {
                if(tl.getChildAt(u) != null)
                    tl.removeViewAt(u);
                u--;
                }
                //do same code over again as above.

                }
            }
        }

This will delete the tableRows and recreate new ones thus "updating" them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM