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 7934107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:32:32+00:00 2026-06-03T21:32:32+00:00

My expected result is in the first launch there will display a progress dialog

  • 0

My expected result is in the first launch there will display a progress dialog to wait for the background thread loading the content. The dialog dismisses after worker thread is done the job. I did search and got this solution How to display progress dialog before starting an activity in Android?

This is my complete code:

    private ManagerApplication app;
    private ImageAdapter adapter;
    private GridView gridview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setupView();      
    }

    private void setupView() {
        gridview = (GridView) findViewById(R.id.gridview);
        app = (ManagerApplication) getApplication();
        ProgressDialog progress = new ProgressDialog(this);
        progress.setMessage("Loading...");
        new LoadImageTask(progress, this).execute();       
    }

    private class LoadImageTask extends AsyncTask<Void, Void, Void> {
        private ProgressDialog progress;
        private Context context;

        public LoadImageTask(ProgressDialog progress, Context context) {
            this.progress = progress;
            this.context = context;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progress.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            adapter = new ImageAdapter(app.getShoes(), context);
            gridview.setAdapter(adapter); 
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            progress.dismiss();
        }

    }

However, my application crashes with the reason that “Only the original thread that created a view hierarchy can touch its views”. I suppose there are something blocked the main UI thread, but its still very unclear. So could anyone point me to the problem ? Thanks

  • 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-06-03T21:32:34+00:00Added an answer on June 3, 2026 at 9:32 pm

    doinBackground is non UI Thread ,So never update any UI(View) in this
    method…

    and use OnPostExecute or OnProgressUpdate for update UI

     @Override
            protected Void doInBackground(Void... params) {
               //here just background task ,
         //its non UI Thread so dont set ant view here set it in OnPostExecute,...
                return null;
            }
    

    call asynctask from setupview

    private void setupView() {
            gridview = (GridView) findViewById(R.id.gridview);
            app = (ManagerApplication) getApplication();
    
            new LoadImageTask(progress, this).execute();       
      }
    

    and create ProgressDilog in OnPreExecute method

    ProgressDialog progress;
    
    @Override
        protected void onPreExecute() {
            super.onPreExecute();
    
         progress = new ProgressDialog(this);
         progress.setMessage("Loading...");
         progress.show();
        }
    

    and in onPostExecute dismiss it

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

Sidebar

Related Questions

Steps: Run the build including unit tests. Expected result: the unit tests are executed
The example code of section 10.6, the expected result is: after several iterations, the
Update: I've corrected the post, so the question is closed. Expected result: Menu width
I'm having some trouble with Excel formats: Example: Value: 13 Expected result: 13 (not
Adding expected types parameter changes response result in unexpected way. Request 1: https://maps.googleapis.com/maps/api/place/search/json?location=38.4551,-122.672045&radius=100&sensor=false&key= Request
ERROR TYPE: Output false false false for @Html.EditorFor(model => model.Items) Expected Result: Listbox with
Almost all of the phpUnit asserts are three parameters: Expected result Actual value Optional
I am having some trouble getting expected results out of the zip command. Cases
In our project, test procedures and expected test results (test specifications) are created in
I have a simple Nhibernate Linq query that is returning more results than expected:

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.