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
精彩评论