0

我在创建图表时使用 processDialog,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 类,但我不知道代码放在哪里。这是 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();
    }


} 

多谢。

4

2 回答 2

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

    }
}
于 2013-10-04T11:24:08.443 回答
0

在这里,进度条没用,所以试试下面的链接android 中的进度条

于 2013-10-04T12:21:20.590 回答