Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:43:10+00:00 2026-05-23T22:43:10+00:00

My main activity calls an AsyncTask when a user clicks a button. This AsyncTask

  • 0

My main activity calls an AsyncTask when a user clicks a button. This AsyncTask performs a fairly long operation, involving a progress dialog. Some of these operations involve adding TableRow views to an existing table in my main activity.

However, my problem is that after the operation is done, these rows are not showing up in the activity GUI. I know that they are being created properly because if I press “Menu” on my phone to get out of my app and then open the app up again, the TableRow views are populated in their respective positions accordingly. Everything looks perfect…the UI thread just isn’t getting reloaded.

Therefore, I am apparently missing a function of some kind to call after the AsyncTask does its duty. Does anyone know what this refresh function might be?

Thank you.

Here is the code:

public void buttonClick(View view) {
    if (view.getId() == R.id.button_begin) {
        cr = this.getContentResolver();
        dialog = new ProgressDialog(this);
        dialog.setCancelable(false);
        dialog.setMessage("Checking...");
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        // reset the bar to the default value of 0
        dialog.setProgress(0);
        // display the progress bar
        dialog.show();
        new mainAsyncTask().execute();
    }

}

    @Override
    protected void onPreExecute() {

        try {
            //create row span so description can overlap columns in the rows
            span = new TableRow.LayoutParams();
            span.span = 3;

            // set the maximum value
            dialog.setMax(numberOfItems.length);
            //initialize facebook
            fb = new FacebookInfo(context, mainActivity, settings, numberOfItems.length, isPaid, settings.getBoolean("checkBoxShareShort", false));
            description = new String[numberOfItems.length];
            factor = new String[numberOfItems.length];
            cool = new String[numberOfItems.length];
            cannot = new String[numberOfItems.length];
            name = new String[numberOfItems.length];
            ivFacebookPub = new ImageView[numberOfItems.length];
            ivShare = new ImageView[numberOfItems.length];
            tableGrid = new TableLayout[numberOfItems.length];

            super.onPreExecute();

            }
            catch (Exception ex) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                ex.printStackTrace(pw);
                table.addView(rowError);
                rowError.addView(tvError, 0, span);
            }
    }


    @Override
    protected Void doInBackground(Void... params) {

        for (int i = 0; i < numberOfItems.length; i++){


            try {

                if (Numbers[i] != null) {


                    if (flag == true) {
                        flag = false;
                    }
                    else if (flag == false) {
                        flag = true;
                    }               
                    fb.addDescription(i, justStuff2[1]);
                    fb.addCannot(i, justStuff2[0]);
                    description[i] = justStuff2[1];
                    cannot[i] = justStuff2[0];
                    //initialize table
                    tableGrid[i] = TableVisuals.createTable(context, flag, i, clickViewContact);    
                    //initialize rows
                    TableRow rowNamePhoto2 = new TableRow(context);
                    TableRow rowCannot2 = new TableRow(context);
                    TableRow rowStuff = new TableRow(context);
                    TableRow rowStuff2 = new TableRow(context);
                    TableRow rowInfo2 = new TableRow(context);
                    TableRow rowShare2 = new TableRow(context);

                    //create rows
                    rowNamePhoto2 = TableVisuals.createRow(context, flag);
                    rowCannot2 = TableVisuals.createRow(context, flag);
                    rowStuff = TableVisuals.createRow(context, flag);

                    //initialize views
                    TextView tvName2 = new TextView(context);
                    ImageView ivPhoto2 = new ImageView(context);
                    ImageView ivArrow2 = new ImageView(context);

                    TextView tvCannot2 = new TextView(context);
                    TextView tvDescription = new TextView(context);

                    //add data to views
                    tvName2 = TableVisuals.getName(context, cr, Numbers[i]);
                    ivPhoto2 = TableVisuals.getPhoto(context, cr, Numbers[i]);
                    ivArrow2 = TableVisuals.getArrowIcon(context, cr, Numbers[i]);
                    tvCannot2 = TableVisuals.getCannot(context, justStuff2[0]);
                    tvDescription = TableVisuals.getStuff(context, justStuff2[1]);

                    //add views to row
                    rowNamePhoto2.addView(ivPhoto2, 0);
                    rowNamePhoto2.addView(tvName2, 1);
                    rowNamePhoto2.addView(ivArrow2, 2);
                    rowCannot2.addView(tvCannot2, 0, span);
                    rowStuff.addView(tvDescription, 0, span);



                    //populate data
                    fb.addName(i, (String)tvName2.getText());
                    name[i] = (String)tvName2.getText();

                    if (isPaid == true) {

                        //create rows
                        rowStuff2 = TableVisuals.createRow(context, flag);
                        rowInfo2 = TableVisuals.createRow(context, flag);

                        //initialize views
                        TextView tvRatio2 = new TextView(context);
                        TextView tvVariance2 = new TextView(context);

                        //add data to views
                        tvRatio2 = TableVisuals.getRatio(context, justStuff2[3]);
                        tvVariance2 = TableVisuals.getVariance(context, justStuff2[2]);

                        //add views to row
                        rowStuff2.addView(tvRatio2, 0, span);
                        rowInfo2.addView(tvVariance2, 0, span);

                        //populate data
                        fb.addCool(i, (String)tvRatio2.getText());
                        fb.addFactor(i, (String)tvVariance2.getText());
                        cool[i] = (String)tvRatio2.getText();
                        factor[i] = (String)tvVariance2.getText();
                        }

                    if (settings.getBoolean("checkBoxSharing", true) == true) {

                        rowShare2 = TableVisuals.createRow(context, flag);
                        ivFacebookPub[i] = TableVisuals.createFacebookPublish(context, i, fb.clickFacebookPublish);
                        //add facebookPublish button
                        rowShare2.addView(ivFacebookPub[i], 0);
                        //add share button
                        ivShare[i] = TableVisuals.createShare(context, i, fb.clickShareResults);
                        rowShare2.addView(ivShare[i], 1);

                        }           
                    //add rows to table
                    tableGrid[i].addView(rowNamePhoto2);
                    tableGrid[i].addView(rowCannot2);
                    if (isPaid) {
                        tableGrid[i].addView(rowStuff2);
                        tableGrid[i].addView(rowInfo2);
                    }
                    tableGrid[i].addView(rowStuff);
                    if (settings.getBoolean("checkBoxSharing", true) == true) {
                    tableGrid[i].addView(rowShare2);
                    }
                    //add table to the main table
                    table.addView(tableGrid[i]);
                    //initialize line
                    TableRow rowLine2 = new TableRow(context);
                    rowLine2 = TableVisuals.createLineRow(context);
                    TextView tvLine2 = new TextView(context);
                    tvLine2 = TableVisuals.createRowLine(context);
                    //add line view
                    rowLine2.addView(tvLine2, 0, span);
                    table.addView(rowLine2);                        
                    }
                publishProgress(i,0);      
    }
            catch (Exception ex) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                ex.printStackTrace(pw);
                publishProgress(i, 1);

            }
        }
        return null;
    }

    @Override
    protected void onProgressUpdate(Integer... value) {
        dialog.setProgress(value[0]);
    }

    @Override
    protected void onPostExecute(Void unused) {
        //close progress bar dialog
        dialog.dismiss();   
         //here is where I try the invalidate and postInvalidate
       table.invalidate();
       for (int i = 0; i < numberOfItems.length; i++) {

           tableGrid[i].invalidate();
       }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:43:10+00:00Added an answer on May 23, 2026 at 10:43 pm

    Sounds like your screen is not being refreshed/redrawn. Is this perhaps in an Adapter? If so, call notifyDataSetChanged() on the adapter. If not, try invalidating your TableLayout by calling invalidate()

    Edit There is a huge fundamental flaw in your implementation. You’re creating UI elements on a non-UI thread. I’m a little surprised your app isn’t crashing, but I suppose if you make them in the background thread it can’t fuss at you for maniputating them on a background thread, but you’re not so lucky when it comes to me :). Everything UI-related needs to be on the UI-thread, whether it be through onProgressUpdate() or in onPostExecute(). I can guarantee your problem stems from this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem in android. i have a main activity who calls a
For tracking user activity, I am using a Windows Hook for the main application
I have a main activity which calls a child one via Intent I =
This has been killing me for two days now. I have a main Activity
This has been killing me for two days now. I have a main Activity
I have an app which has a main activity that calls other activities on
I have a couple AsyncTask classes in my main activity, each of which fetches
In my main activity, I have the following code that calls my FileBrowser activity:
I have a widget that supposed to call an Activity of the main app
The main activity includes some variables with set values. I created a sub-activity with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.