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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:42:59+00:00 2026-05-25T11:42:59+00:00

In my app when i click button the progress bar will be started lately.

  • 0

In my app when i click button the progress bar will be started lately. I want to start start quickly. please can anybody help me. bshowgifts listener in onCreate().

bShowGifts.setOnClickListener(new OnClickListener()  
{                          

@Override        
        public void onClick(View v) 
        {               
            //vsChange
            progressDlg = ProgressDialog.show(Ehome.this, "", "", true);                            
            progressDlg.setContentView(R.layout.custom_dialog);                
            //Gender and age must be selected
            if(ElGiftoAppData.getAppData().arSelectedGender.size() == 0)  
            {
                progressDlg.dismiss();  
                String strMsg = "Please select a gender";
                DisplaySelectionMessage(strMsg);             
                return;
            }

            if(ElGiftoAppData.getAppData().arSelectedAge.size() == 0)
            {
                progressDlg.dismiss();
                String strMsg = "Please select an age";  
                DisplaySelectionMessage(strMsg);               
                return;
            }

            if(nMatchingGifts == 0)
            {
                progressDlg.dismiss(); 
                tvCount = (TextView) findViewById(R.id.textMatchinGifts);
                String strContent = "# of Matching Gifts: 0";
                tvCount.setText(strContent);                                                        
                String strMsg = "No gifts found! Please change the search criteria.";
                DisplaySelectionMessage(strMsg);               
                return; 
            }               

            try
            {                   
                //Thread for getting the negative attributes values
                Thread tDisplayCategories = new Thread() 
                {
                    public void run()
                    {  


                        System.out.println("Showgifts : Thread:run");
                        handlerDisplayGifts.post(call_ShowGiftsCategoryPage);
                    }                                                                                          
                };
                tDisplayCategories.start();
            }
            catch(Exception exp)
            {
                progressDlg.dismiss();
            }
            return;
            }         
    });

    public void DisplaySelectionMessage(String strMsg)
{

            //display alert dialog            
    AlertDialog alertDialog = new AlertDialog.Builder(Ehome.this).create();
    alertDialog.setTitle("Elgifto Alert");
    alertDialog.setMessage(strMsg);
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() 
    {           
        public void onClick(DialogInterface dialog, int id) 
        {                
            dialog.cancel();
        }
    });

    alertDialog.show();
    return;
}

Updated code

bShowGifts.setOnClickListener(new OnClickListener()  

{                          
        @Override        
            public void onClick(View v) 
        {               
          new showgiftsbtn().execute();
            }         
});

public class showgiftsbtn extends AsyncTask<Void, Void, Void>

{

private final ProgressDialog dialog = new ProgressDialog(Ehome.this);

        protected void onPreExecute()
        {
            this.dialog.setMessage("Please Wait...");
            this.dialog.show();



        // put your code which preload with processDialog  
        if(ElGiftoAppData.getAppData().arSelectedGender.size() == 0)  
        {
            dialog.dismiss();  
            String strMsg = "Please select a gender";
            DisplaySelectionMessage(strMsg);             
            return;
        }

        if(ElGiftoAppData.getAppData().arSelectedAge.size() == 0)
        {
            dialog.dismiss();
            String strMsg = "Please select an age";  
            DisplaySelectionMessage(strMsg);               
            return;
        }

        if(nMatchingGifts == 0)
        {
            dialog.dismiss(); 
            tvCount = (TextView) findViewById(R.id.textMatchinGifts);
            String strContent = "# of Matching Gifts: 0";
            tvCount.setText(strContent);                                                        
            String strMsg = "No gifts found! Please change the search criteria.";
            DisplaySelectionMessage(strMsg);               
            return; 
        }               

        try
        {                   
            //Thread for getting the negative attributes values
            Thread tDisplayCategories = new Thread() 
            {
                public void run()
                {  
                    System.out.println("Showgifts : Thread:run");
                    handlerDisplayGifts.post(call_ShowGiftsCategoryPage);
                    dialog.dismiss();
                }                                                                                          
            };
            tDisplayCategories.start();
        }
        catch(Exception exp)
        {
            dialog.dismiss();
        }
    }

    @Override
    protected Void doInBackground(Void... arg0)
    {           
        // put you code here
        return null;
    }
    protected void onPostExecute(final Void unused)
    {           

    }
}
  • 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-25T11:43:00+00:00Added an answer on May 25, 2026 at 11:43 am

    try this::
    AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

    An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute

        private class xyz extends AsyncTask<Void, Void, Void> {
                    private final ProgressDialog dialog = new ProgressDialog(tranning.this);
    
                    protected void onPreExecute() {
                        this.dialog.setMessage("Please Wait...");
                        this.dialog.show();
    
                        // put your code which preload with processDialog  
    
    
                @Override
                protected Void doInBackground(Void... arg0) {
    
                    // put you code here
    if(ElGiftoAppData.getAppData().arSelectedGender.size() == 0)  
                {
    
                    String strMsg = "Please select a gender";
                    DisplaySelectionMessage(strMsg);             
                    return;
                }
    
                if(ElGiftoAppData.getAppData().arSelectedAge.size() == 0)
                {
                    progressDlg.dismiss();
                    String strMsg = "Please select an age";  
                    DisplaySelectionMessage(strMsg);               
                    return;
                }
    
            if(nMatchingGifts == 0)
            {
    
                tvCount = (TextView) findViewById(R.id.textMatchinGifts);
                String strContent = "# of Matching Gifts: 0";
                tvCount.setText(strContent);                                                        
                String strMsg = "No gifts found! Please change the search criteria.";
                DisplaySelectionMessage(strMsg);               
                return; 
            }               
    
            try
            {                   
                //Thread for getting the negative attributes values
                Thread tDisplayCategories = new Thread() 
                {
                    public void run()
                    {  
    
    
                        System.out.println("Showgifts : Thread:run");
                        handlerDisplayGifts.post(call_ShowGiftsCategoryPage);
                    }                                                                                          
                };
                tDisplayCategories.start();
            }
            catch(Exception exp)
            {
    
            }
                }
    
                    return null;
                }
    protected void onPostExecute(final Void unused) {
                    if (this.dialog.isShowing()) {
                      this.dialog.dismiss();
    
                    }
    
                }
            }
    

    and use this in your button click event ::

     new xyz().execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Swing app, users can click a button to open a dialog panel
I need a function that a user can just click a flash app button
I want to make a right click menu for my winforms app. It will
i am Developing app for Blackberry.in button click event i want to hide/invisible verticalFieldManager
In my project's main ViewController, once users of the app click the Start button,
i want to click a button to change Views in iphone app . I
I'm in the midst of writing a slide show app (click a button, and
Hello StackOverflow'ers, I have a (flex) app that, on the click of a button,
when i click a button my app should be terminated. It must not to
i am making a app which takes photo on button click i have camera.java

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.