我在创建图表时使用processDialog,processDialog出现但不旋转。我搜索过,我需要使用Async Task,但我没有把代码放在哪里:
这是我的代码:
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类,但我不知道放在哪里代码。 这是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();
}
}
非常感谢。
答案 0 :(得分:1)
试试这个,
public class ProgressTask extends AsyncTask <Void,Void,Void>
{
@Override
protected void onPreExecute()
{
startProgressDialog(v);
}
@Override
protected Void doInBackground(Void... arg0)
{
// TODO Auto-generated method stub
return null;
}
@Override
protected void onPostExecute(Void result)
{
progressBar.dismiss();
irGraficaComparativa(null);
}
}
答案 1 :(得分:0)
在此处,进度条无用,请尝试以下链接Progress bar in android