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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:41:36+00:00 2026-06-15T12:41:36+00:00

I want to show a Progress Dialog on button click in my app while

  • 0

I want to show a Progress Dialog on button click in my app while data is loaded from the internet. I can’t get it to work, could someone give me some tips on where to put the Dialog function?

This is my AsyncTask method:

private class GetTweets extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... twitterURL) {
            //start building result which will be json string
            StringBuilder tweetFeedBuilder = new StringBuilder();
            //should only be one URL, receives array
            for (String searchURL : twitterURL) {
                HttpClient tweetClient = new DefaultHttpClient();
                try {
                    //pass search URL string to fetch
                    HttpGet tweetGet = new HttpGet(searchURL);
                    //execute request
                    HttpResponse tweetResponse = tweetClient.execute(tweetGet);
                                            StatusLine searchStatus = tweetResponse.getStatusLine();
                    if (searchStatus.getStatusCode() == 200) {
                        //get the response
                        HttpEntity tweetEntity = tweetResponse.getEntity();
                        InputStream tweetContent = tweetEntity.getContent();
                                                    InputStreamReader tweetInput = new InputStreamReader(tweetContent);
                        BufferedReader tweetReader = new BufferedReader(tweetInput);
                        String lineIn;
                        while ((lineIn = tweetReader.readLine()) != null) {
                            tweetFeedBuilder.append(lineIn);
                        }
                    }
                    else
                        tweetDisplay.setText("Error!");
                }
                catch(Exception e){ 
                    tweetDisplay.setText("Error!");
                    e.printStackTrace(); 
                }
            }
            //return result string
            return tweetFeedBuilder.toString();
        }
                    protected void onPostExecute(String result) {
            //start preparing result string for display
            StringBuilder tweetResultBuilder = new StringBuilder();
            try {
                //get JSONObject from result
                JSONObject resultObject = new JSONObject(result);
                //get JSONArray contained within the JSONObject retrieved - "results"
                JSONArray tweetArray = resultObject.getJSONArray("results");
                //loop through each item in the tweet array
                for (int t=0; t<tweetArray.length(); t++) {
                    //each item is a JSONObject
                    JSONObject tweetObject = tweetArray.getJSONObject(t);
                                        tweetResultBuilder.append(tweetObject.getString("from_user")+": ");
                    tweetResultBuilder.append(tweetObject.get("text")+"\n\n");
                }
            }
            catch (Exception e) {
                tweetDisplay.setText("Error!");
                e.printStackTrace();
            }
            //check result exists
            if(tweetResultBuilder.length()>0)
                tweetDisplay.setText(tweetResultBuilder.toString());
            else
                tweetDisplay.setText("no results!");
        }
    }
  • 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-15T12:41:38+00:00Added an answer on June 15, 2026 at 12:41 pm

    In the AsyncTask class use onPrexecute method to display progress dialog and use onPostExecute to dismiss it:

        @Override
        protected void onPreExecute()
        {
            super.onPreExecute();
            pDialog = new ProgressDialog(YOUR_ACTIVITY_CLASS_NAME.this);
            pDialog.setMessage("Please Wait");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }
    
        @Override
        protected void onPostExecute(String str)
        {
            // Dismiss the dialog once finished
            pDialog.dismiss();  
        }
    

    Don’t forget to define pDialog before you call it:

     ProgresDialog pDialog;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my app when i click a button i am getting some data from
I want to show the progress dialog while loading the images in grid view.
hii I want show a pop up Dialog box when i click on to
Possible Duplicate: Android: ProgressDialog.show() crashes with getApplicationContext I want to have a progress dialog
I want to show ProgressDialog when I click on Login button and it takes
I want a progress dialog saying Please Wait , while my code downloads and
I want to load an image from url on a button click & to
I want to show a progress dialog when my activity is busy preparing something.
I want to create such a dialog to show progress bar like I have
In my app when i click button the progress bar will be started lately.

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.