0
如何顯示進度條我打電話意圖從A級到B級。 在哪個B級從使用解析手段加載數據,而 發生這種情況我收到空白屏幕在這個時候我想顯示 progressbar我該怎麼做。如何在從遠程數據庫加載數據時在android中顯示進度條?
現在,我寫的代碼如下..
class A extends Activity{
oncreate(){
...
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new performBackgroundtask().execute();
}
}
class performBackgroundtask extends AsyncTask<Void, Void, Void> {
//
ProgressDialog progressDialog = new ProgressDialog(Main.this);
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(Main.this,"", "Please wait...");
super.onPreExecute();
/*
* progressDialog.setMessage("Please wait while loading ...");
* progressDialog.show(); progressDialog.setCancelable(true);
*/
}
@Override
protected Void doInBackground(Void... params) {
Intent in = new Intent(A.this, B.class);
startActivity(in);
// TODO Auto-generated method stub
return null;
}
@Override
protected void onPostExecute(Void result) {
progressDialog.dismiss();
}
}
}
class B { ...
/*
* In which this class has another view which has to get the data from
* URL using SAXPArsing.
*
* ... for this where i need to write progress bar code.
*/
}
你在做AsyncTask的doInBackground(Void ... params)方法嗎? – user370305
意圖調用另一個需要從服務器加載數據的類。 – Harish