Question

I have a method which is list my items from a server. Therefore, this method takes time until getting all the items. So I want to use ProgressDialog for waiting this method. I read some modules but I couldnt find any useful solution.

    public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            // setContentView(R.layout.main;
                    loginScreen();
        }
    public boolean getItems() throws MessagingException 
           {
                    items receiving here
           }
    public void loginScreen() 
           {
                   setContentView(R.layout.main);
                   Button loginBtn = (Button) findViewById(R.id.btnLogin);

                   loginBtn.setOnClickListener(new Button.OnClickListener() 
                     {          
                      public void onClick(View arg0) 
                       {
                          getItems();
                       }
                     }
           }

On button Click I call the method which received all items. When I click the button I want to show a progressbar until all items getting.

Was it helpful?

Solution

create an AsyncTask which shows an ProgressBar on getItems(). You need an AsyncTask because the main Thread will be busy fetching stuff from server and ProgressBar won't show up untill that is finished.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top