dulal_026
dulal_026

Reputation: 579

Progress bar problem in android

I have create an android quiz application where i loaded all of question from web service. For this in oncreate method i wrote following

public void onCreate(Bundle savedInstanceState) 
        {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.testlayoutforimage);

           loadControls();
           getPassingValue();


            ParserMethod parserMethod=new ParserMethod();
            //questionsObj=parserMethod.parseQuestionDetailsFor(passingFeature,numOfQuestion,passingSubject,passingChapter);
            questionsObj=parserMethod.parseQuestionImages(passingSubject,passingFeature,passingChapter;
}

But problem is that when the question is loaded it take some time . I want to add a progress bar. When the page is loaded then the progress is shown and the question is load . After that the bar is remove and Display the ques .how can i do this.

Upvotes: 0

Views: 391

Answers (2)

ngesh
ngesh

Reputation: 13501

Using AsyncTask.. just like below.. code is not exactly right.. its just to give an idea..

classs backgrnd extends Asynctask{

protected object onPreExecute(){
//display dialog
}

protected object doInBackgroung(Object... arg){
//fetch data
}

protected object onPostExecute(Object result){
//dismiss dialog
}
}

Upvotes: 2

Rasel
Rasel

Reputation: 15477

You can Use AsyncTask class for this.The class is designed so that you can do something in the background.It has overridden method onPreExecute where you can show the ProgressDialog and on doInBackground method load your question.On preExecute method cancel the dialog and update your UI

Upvotes: 1

Related Questions