2011-07-27 58 views
0

我已经创建了一个android测验应用程序,其中我从web服务加载所有问题。对于这种在onCreate方法我写了下面的Android中的进度条问题

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

但问题是,当问题被加载它需要一定的时间。 我想添加一个进度条。当页面被加载时,显示进度并且问题是加载。之后,酒吧是删除和显示问题。我可以做到这一点。

回答

2

使用的AsyncTask ..就像下面..代码是不完全正确的..它只是给一个想法..

classs backgrnd extends Asynctask{ 

protected object onPreExecute(){ 
//display dialog 
} 

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

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

您可以使用这一信息。class的AsyncTask类的设计,使你可以在background.It事情已经覆盖方法onPreExecute在那里你可以显示ProgressDialog和doInBackground方法加载question.On preExecute方法取消对话和更新UI