我在創建圖表時使用了processDialog,processDialog出現但不旋轉。我搜索,我需要使用異步任務,但我沒有,我必須把代碼:在AsyncTask中運行ProcessDialog的問題
這是我的代碼:
bCrearGraf2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startProgressDialog(v);
irGraficaComparativa(null);
}
});
startProgressDialog()是這樣的:
public void startProgressDialog(View V)
{
progressBar = new ProgressDialog(V.getContext());
progressBar.setCancelable(true);
progressBar.setIndeterminate(true);
progressBar.setMessage("Creating chart");
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.show();
}
irGraficaComparativa()啓動新的活動:
public void irGraficaComparativa(View view){
Intent i =new Intent(this,Graficas_comparativa.class);
i.putExtra("Id_vehiculo1",idVehChar1);
i.putExtra("Nomb_vehiculo1",nombVeh1);
i.putExtra("Id_vehiculo2",idVehChar2);
i.putExtra("Nomb_vehiculo2",nombVeh2);
Log.d("Veh1","Nombre: " + nombVeh1 + " ID: " + idVehChar1);
Log.d("Veh1","Nombre: " + nombVeh2 + " ID: " + idVehChar2);
startActivity(i);
}
進入我創建的AsyncTask類的活動,BU我不知道把代碼放在哪裏。 這個的AsyncTask類:
public class ProgressTask extends AsyncTask <Void,Void,Void>{
@Override
protected void onPreExecute(){
}
@Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
protected void onPostExecute(Void result) {
progressBar.dismiss();
}
}
非常感謝。
將顯示onPreExecute代碼()進度對話框方法 和解聘代碼onPostExecute (Void結果)方法 –