开发者

Progress bar problem in android

开发者 https://www.devze.com 2023-03-23 17:18 出处:网络
I have create an android quiz application where i loaded all of question from web service. For this in oncreate method i wrote following

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开发者_StackOverflow社区 . 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.


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
}
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号