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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:08:43+00:00 2026-06-04T08:08:43+00:00

I’m trying to show a loading icon to the user when the application makes

  • 0

I’m trying to show a loading icon to the user when the application makes a query to online Database. I’ve tried using a AnimationDrawable (I gave up because there was no need of a custom icon), ProgressDialog and ProgressBar.
The ProgressBar seems most appropriate, since I don’t want a message, just a spinning icon. But I can not even make a ProgressBar appear on the screen, doesn’t matter where I call it.
I’ve got the ProgressDialog appearing in screen, but it only appears after the server’s response, and if I use dismiss() or cancel() it doesn’t even appear at all.

I’ve had any success using AsyncTasks or Threads.

In the app, there is a class JogarActivity.java that attemps to show a list of options. It receives some parameters like the user id, and calls UserFunctions:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

    setContentView(R.layout.jogar_layout);
    Intent in = getIntent();
    String url = this.getString(R.string.urlSite);
    ArrayList<HashMap<String, String>> respostaList = new ArrayList<HashMap<String, String>>();

    String idt = in.getStringExtra(TAG_ID);
    primeiraPergunta = in.getBooleanExtra(TAG_PRIMEIRAPERGUNTA, true);

    TextView insertPergunta = (TextView) findViewById(R.id.insertPergunta);
    ListView insertRespostas = (ListView) findViewById(R.id.listResposta);

    SharedPreferences settings = getSharedPreferences("PREFS_LOGIN", MODE_PRIVATE);
    Integer idUsuario = settings.getInt("idUsuario", 0);
    String idUser = idUsuario.toString();


    if (primeiraPergunta){
        UserFunctions userFunction = new UserFunctions();
        json = userFunction.getJogar(idt, idUser);
    }else{
        try {
            json = new JSONArray(in.getStringExtra(TAG_JSON));
            json = json.getJSONArray(2);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

Below is the getJogar function in userFunctions:
public JSONArray getJogar(String categoria, String usuarioId){
List params = new ArrayList();

    params.add(new BasicNameValuePair("categoria", categoria));
    params.add(new BasicNameValuePair("idUsuario", usuarioId));
    JSONArray json = jsonParser.getJSONFromUrl(perguntaURL, params);

    return json;
}

JSONParser.java is the class that makes the httpRequest:
public JSONArray getJSONFromUrl(String url, List params) {

    // Making HTTP request
    try {
        // defaultHttpClient
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));



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



        // json = EntityUtils.toString(httpEntity);
        // HttpEntity httpEntity2 = httpEntity;
        json = EntityUtils.toString(httpEntity);
        // is = httpEntity.getContent();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } 
            //then makes the JSON manipulation

As long as JSONParser and userFunctions aren’t activities, I couldn’t use ProgressDialogs inside them (Can’t get the application context). All server requests are made in JSONParser.java, that’s why i’ve first tried to put the ProgressDialog/ProgressBar there.

The closest that i’ve reached was using this code in JogarActivity (It shows the ProgressDialog, but after getting server’s response. And if I use dismiss, it doesn’t even appears)

   final ProgressDialog loader = new ProgressDialog(JogarActivity.this);
    loader.show();
    //...the if-else code i've pasted above
    loader.dismiss();

Even using runOnUiThread it doesn’t works! I’m getting without options…

Thanks for all help.

  • 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-04T08:08:44+00:00Added an answer on June 4, 2026 at 8:08 am

    this worked:

    public class RegisterActivity extends Activity{
    EditText reg_fullname;
    EditText reg_email;
    EditText reg_login;
    EditText reg_password;
    EditText reg_password2;
    Spinner reg_country;
    Spinner reg_genre;
    EditText reg_birthday;
    EditText reg_promocode;
    Button btnRegister;
    Context ctx = this;
    ProgressDialog pDialog;
    JSONArray json;
    String status;
    String msg;
    
    String fullname;
    String email;
    String login;
    String password;
    String password2;
    String country;
    String genre;
    String birthday;
    String promocode;
    
    boolean finishActivity = false;
    
    /**
     * @see android.app.Activity#onCreate(Bundle)
     */
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.register);
    
        TextView loginScreen = (TextView) findViewById(R.id.link_to_login);
    
        loginScreen.setOnClickListener(new View.OnClickListener() {
    
            public void onClick(View arg0) {
                                // Closing registration screen
                // Switching to Login Screen/closing register screen
                finish();
            }
        });
    
        reg_fullname = (EditText) findViewById(R.id.reg_fullname);
        reg_email = (EditText) findViewById(R.id.reg_email);
        reg_login = (EditText) findViewById(R.id.reg_login);
        reg_password = (EditText) findViewById(R.id.reg_password);
        reg_password2 = (EditText) findViewById(R.id.reg_password2); //confirmação de senha
        reg_country = (Spinner) findViewById(R.id.reg_country);
        reg_genre = (Spinner) findViewById(R.id.reg_genre);
        reg_birthday = (EditText) findViewById(R.id.reg_birthday);
        reg_promocode = (EditText) findViewById(R.id.reg_promocode);
    
        btnRegister = (Button) findViewById(R.id.btnRegister);
    
    
        btnRegister.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
    
                fullname = reg_fullname.getText().toString();
                email = reg_email.getText().toString();
                login = reg_login.getText().toString();
                password = reg_password.getText().toString();
                password2 = reg_password2.getText().toString();
                country = reg_country.getSelectedItem().toString();
                genre = reg_genre.getSelectedItem().toString();
                birthday = reg_birthday.getText().toString();
                promocode = reg_promocode.getText().toString();
    
                boolean validation = true;
                String message = "Campo de preencimento obrigatório";
    
                if(fullname.equalsIgnoreCase("")){
                    reg_fullname.setError(message);
                    validation = false;
                }
                if(email.equalsIgnoreCase("")){
                    reg_email.setError(message);
                    validation = false;
                }
                if(!email.matches(".*@.*")){
                    reg_email.setError("O endereço de email não é válido");
                    validation = false;
                }
                if(login.equalsIgnoreCase("")){
                    reg_login.setError(message);
                    validation = false;
                }
                if(password.equalsIgnoreCase("")){
                    reg_password.setError(message);
                    validation = false;
                }
                if(password2.equalsIgnoreCase("")){
                    reg_password2.setError(message);
                    validation = false;
                }
                if(!password.equals(password2)){
                    reg_password2.setError("A confirmação de senha não confere");
                    validation = false;
                }
                if(birthday.equalsIgnoreCase("")){
                    reg_birthday.setError(message);
                    validation = false;
                }
                SimpleDateFormat bd = new SimpleDateFormat("dd/MM/yyyy");
                if(bd.parse(birthday, new ParsePosition(0)) == null){
                    reg_birthday.setError("Esta data não é válida! Preencha novamente, usando o formato dd/mm/aaaa");
                    validation = false;
                }
    
                if(validation){
                new Register().execute();
                }
    
            }
        });
    
    
    
    }
    
    
    class Register extends AsyncTask<Void, Void, JSONArray>{
    
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(ctx);
        pDialog.setMessage("Aguarde...");
        pDialog.setIndeterminate(true);
        pDialog.setCancelable(false);
        pDialog.show();
    }
    
    @Override
    protected JSONArray doInBackground(Void... params) {
        UserFunctions userFunction = new UserFunctions();
        json = userFunction.newUser(fullname, email, login, password, country, genre, birthday, promocode);
    
        return json;
    
    }
    
    protected void onPostExecute(JSONArray result) {
        // dismiss the dialog once done
        pDialog.dismiss();
        final AlertDialog alertDialog = new AlertDialog.Builder(
                RegisterActivity.this).create();
    
                try {
                    status = json.getString(0);
                    msg = json.getString(1);
                    Log.d("Status", status);
                } catch (JSONException e) {
                    Log.e("RegisterActiviry", "Error converting result " + e.toString());
                    e.printStackTrace();
                    status = null;
                }
    
                if (status.equalsIgnoreCase("erro")){
                    alertDialog.setTitle("Erro");
                    alertDialog.setMessage(msg);
    
                }else if (status.equalsIgnoreCase("sucesso")){
                    alertDialog.setTitle("Sucesso!");
                    alertDialog.setMessage(msg);
                    finishActivity = true;
                }else{
                    alertDialog.setTitle("Erro");   
                    alertDialog.setMessage("Não foi possível realizar seu cadastro, tente novamente mais tarde.");
                }
    
    
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        if(finishActivity){
                        finish();
                        }else{
                            alertDialog.dismiss();
                        }
                    }
            });
    
            alertDialog.show();
    
    }
    
    }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

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.