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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:47:22+00:00 2026-05-23T14:47:22+00:00

I would like my app to start with a ProgressDialog while it connects to

  • 0

I would like my app to start with a ProgressDialog while it connects to an online resource, grabs the data, parses it, and then fills a spinner with it. DirectoryTransaction.doDepts() in the code below is what connects and parses the data into the String[][] DeptResults. I’ve tried other questions and answers to no success, and would really like to get this to work. As it is now, the application appears to freeze for a few seconds while it does all this work. I’d much rather have it show the dialog instead.

Here’s the code as I have it now:

package com.test.directory;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class Directory extends Activity {

    public static boolean test = false;
    public static int Start = 1;
    public static int Page = 1;
    public static int ResultsCount = 0;
    public static int sdk = new Integer(Build.VERSION.SDK).intValue();
    public static String[] Fields = new String[6];
    public static String[][] DeptResults;
    public static String[][] ReturnResults;
    public static String[] ResultsDetails = new String[11];

    public EditText fname = (EditText) findViewById(R.id.fname);
    public EditText lname = (EditText) findViewById(R.id.lname);
    public EditText aim = (EditText) findViewById(R.id.aim);
    public EditText phone = (EditText) findViewById(R.id.phone);
    public Spinner depts = (Spinner) findViewById(R.id.dept);


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.searchscreen);

        DirectoryTransaction.doDepts();

        //Sets up and fills the department spinner
        final ArrayAdapter<CharSequence> deptsAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item);
        deptsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        depts.setAdapter(deptsAdapter);
        for(int i = 0 ; i < DeptResults.length ; i++){
            deptsAdapter.add(DeptResults[i][0]);            
        }

        //Search button
        findViewById(R.id.search).setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                Start = 1;
                Page = 1;

              //Put all the info from the fields into a string array
                Fields[0] = fname.getText().toString();
                Fields[1] = lname.getText().toString();
                Fields[2] = aim.getText().toString();
                Fields[3] = phone.getText().toString();
                Fields[4] = DeptResults[(int)depts.getSelectedItemId()][1];
                Fields[5] = Integer.toString(Start);

                DirectoryTransaction.doSearch(Directory.Start, Fields[0], Fields[1], Fields[2], Fields[4], Fields[3]);


              //Shows error if more than 300 results
                if(ResultsCount > 300){
                    Toast.makeText(Directory.this, "Too many results found, please narrow your search.", Toast.LENGTH_LONG).show();
                }else{              
              //Load a new Intent and start the results activity
                Intent i = new Intent(v.getContext(), DirectoryResults.class);
                startActivity(i);
                }
            }
        });

        //Clear Button
        findViewById(R.id.clear).setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                //Clears all the fields, sets the Spinner to 0.
                fname.setText("");
                lname.setText("");
                aim.setText("");
                phone.setText("");
                depts.setSelection(0);
            }
        });
    }
}

Basically, this is what I want to do while a ProgressDialog shows.

        DirectoryTransaction.doDepts();

        //Sets up and fills the department spinner
        final ArrayAdapter<CharSequence> deptsAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item);
        deptsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        depts.setAdapter(deptsAdapter);
        for(int i = 0 ; i < DeptResults.length ; i++){
            deptsAdapter.add(DeptResults[i][0]);            
        }

Any ideas / examples that can show me what I need? I’ve looked at quite a few and haven’t been able to figure it out.

Thanks, I got it working. I’m not sure if I need it to be so I’ll play around with it. Here’s the code:

package com.test.directory;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class Directory extends Activity {

    public static boolean test = false;
    public static int Start = 1;
    public static int Page = 1;
    public static int ResultsCount = 0;
    public static int sdk = new Integer(Build.VERSION.SDK).intValue();
    public static String[] Fields = new String[6];
    public static String[][] DeptResults;
    public static String[][] ReturnResults;
    public static String[] ResultsDetails = new String[11];

    public ArrayAdapter<CharSequence> deptsAdapter;

    ProgressDialog dialog;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.searchscreen);

        new getAllData().execute(this);

        final EditText fname = (EditText) findViewById(R.id.fname);
        final EditText lname = (EditText) findViewById(R.id.lname);
        final EditText aim = (EditText) findViewById(R.id.aim);
        final EditText phone = (EditText) findViewById(R.id.phone);
        final Spinner depts = (Spinner) findViewById(R.id.dept);

        //Sets up and fills the department spinner
        deptsAdapter = new ArrayAdapter<CharSequence>(Directory.this, android.R.layout.simple_spinner_item);
        deptsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        depts.setAdapter(deptsAdapter);

      //Search button
        findViewById(R.id.search).setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                Start = 1;
                Page = 1;

              //Put all the info from the fields into a string array
                Fields[0] = fname.getText().toString();
                Fields[1] = lname.getText().toString();
                Fields[2] = aim.getText().toString();
                Fields[3] = phone.getText().toString();
                Fields[4] = DeptResults[(int)depts.getSelectedItemId()][1];
                Fields[5] = Integer.toString(Start);

                DirectoryTransaction.doSearch(Directory.Start, Fields[0], Fields[1], Fields[2], Fields[4], Fields[3]);


              //Shows error if more than 300 results
                if(ResultsCount > 300){
                    Toast.makeText(Directory.this, "Too many results found, please narrow your search.", Toast.LENGTH_LONG).show();
                }else{
              //Load a new Intent and start the results activity
                Intent i = new Intent(v.getContext(), DirectoryResults.class);
                startActivity(i);
                }
            }
        });

      //Clear Button
        findViewById(R.id.clear).setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              //Clears all the fields, sets the Spinner to 0.
                fname.setText("");
                lname.setText("");
                aim.setText("");
                phone.setText("");
                depts.setSelection(0);
            }
        });
    }

    private class getAllData extends AsyncTask<Context, Void, Cursor> {
        protected void onPreExecute () {
            dialog = ProgressDialog.show(Directory.this, "", 
                    "Loading. Please wait...", true);
        }

        @Override
        protected Cursor doInBackground(Context... params) {
            DirectoryTransaction.doDepts();

            return null;
        }

        protected void onPostExecute(Cursor c) {

            for(int i = 0 ; i < DeptResults.length ; i++){
                deptsAdapter.add(DeptResults[i][0]);            
            }
            //update the UI or do soemthing
            dialog.dismiss();
        }
    }

}
  • 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-23T14:47:23+00:00Added an answer on May 23, 2026 at 2:47 pm

    Here is how I do it:

    I put ProgressDialog dialog; at the top of my class file.

    In my onCreate() method I have this:

    new getAllData().execute(this);   
    

    Since my task takes a bit of time I make it run in a background thread (and if your app is ‘freezing’ I would suggest doing the same). The code for the background thread looks like:

     private class getAllData extends AsyncTask<Context, Void, Cursor> {
        protected void onPreExecute () {
            dialog = ProgressDialog.show(Shows.this, "", 
                    "Loading shows. Please wait...", true);
        }
    
        @Override
        protected Cursor doInBackground(Context... params) {
            //do all the work
        }
    
        protected void onPostExecute(Cursor c) {
            //update the UI or do soemthing
            dialog.dismiss();
        }
    }
    

    More info on ASync here: http://developer.android.com/reference/android/os/AsyncTask.html

    If you were going to use Async, your onPreExecute would display the dialog, the doInBackground() would get whatever you need to get from the web, and then onPostExecute() would stick everything into your spinner.

    If you don’t want to do that then you can still do the ProgressDialog.show(…) and dialog.dimiss() on finish

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

Sidebar

Related Questions

I would like to create a file format for my app like Quake, OO,
I would like to post-process my app.config file and perform some token replacements after
I would like to create an iPhone app that can open the google maps
I would like to add OpenId support to an app. It runs on ASP.NET
I would like to make a simple web app that displays 20 or so
I would like to override the use of the standard app.config by passing a
I would like to provide two different versions of my iPhone app on the
In an app I'm coding I would like to make an alert message to
I would like to show an XML file in my .NET 2.0 WinForms app
I have a Pylons app where I would like to move some of the

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.