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

  • Home
  • SEARCH
  • 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 6645527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:17:54+00:00 2026-05-26T00:17:54+00:00

How do I add a Progress Bar when a user selects a spinner item

  • 0

How do I add a Progress Bar when a user selects a spinner item that triggers a http request. Do I add it to the class doing the http request (dataCall) or the main activity that has the spinner in it?

I have a class DataCall that when called does a http call to a php script that gets data from a MySQL database and returns data in a JSON format. This class is called after a spinner item is selected. The data returned is added to another spinner in the same activity. I am trying to show the progress wheel when the class DataCall is doing its thing. Below is my code for calling DataCall from my MainActivity and the code from DataCall .

MainActivity that calls DataCall (See below) when the spinner is selected. When DataCall returns data it updates another spinner with the new data.

statespinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
     public void onItemSelected(AdapterView<?> parent, View view, int position,long arg3) 
     {
      int id = parent.getId();

      if (spinner1_count2 < spinner1_count1 ) {
          spinner1_count2++;  } 
         else 
         {
             city.clear();
             String item = statespinner.getSelectedItem().toString();
             String spinnerContentType = "city";
             String spinnerURL = "getStoreCity.php?state=" + item;


//CALLING DATACALL BELOW
                 String city_data =  DataCall.getJSON(spinnerURL,spinnerContentType);
             Log.d(TAG, city_data);
             String state_spinner_log = "STATE SPINNER";
             Log.d(TAG, state_spinner_log);

             JSONArray jsonArray;    
             try {

                 cityjsonArray = new JSONArray(city_data);


                 for (int i=0; i<cityjsonArray.length(); i++)
                 {   
                     String styleValue2 = cityjsonArray.getJSONArray(i).getString(0);    
                     Log.d(TAG, styleValue2);
                     city.add(styleValue2);
                     adapter2.notifyDataSetChanged();

                 }
                //

                 } catch (JSONException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                 }




          }

     }
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub

        }

    });

DataCall Class:

 public class DataCall extends Activity {
        private static final String TAG = "MyApp";


         public static String getJSON(String myUrlString, String contentType){  

                    String line = null;
                    String tag_value = null;
                    try {

                        DefaultHttpClient httpClient = new DefaultHttpClient();

                        HttpGet httpPost = new HttpGet("http://www.mywebsite.com/getdata/" + myUrlString);

                        HttpResponse httpResponse = httpClient.execute(httpPost);
                        HttpEntity httpEntity = httpResponse.getEntity();
                        line = EntityUtils.toString(httpEntity);

                    } catch (UnsupportedEncodingException e) {
                        line = "<results status=\"error\"><msg>Can't connect to server1</msg></results>";
                    } catch (MalformedURLException e) {
                        line = "<results status=\"error\"><msg>Can't connect to server2</msg></results>";
                    } catch (IOException e) {
                        line = "<results status=\"error\"><msg>Can't connect to server3</msg></results>";
                    }catch (Exception anything) {
                        //Whatever

                    }

                    return line;

            }


    }
  • 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-26T00:17:54+00:00Added an answer on May 26, 2026 at 12:17 am

    I think you’re going to have to move this web call out to a different thread as it will take an unknown amount of time to run and may cause an ANR.

    If you use ASyncTask it has an inbuilt mechanism for updating a progress bar as the background thread runs. There is a lot of valuable information at this link

    http://www.vogella.de/articles/AndroidPerformance/article.html

    Hope this helps, m

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

Sidebar

Related Questions

No related questions found

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.