0

I use a processDialog while creating a charts, the processDialog appears but dont spin. I searched and I need use Async Task, but I dont have where I have to put the code:

This is my code:

bCrearGraf2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                startProgressDialog(v);
                irGraficaComparativa(null);


                }
        }); 

startProgressDialog() is this:

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() start the new activity:

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

} 

Into the activity I create a AsyncTask class, but I dont know where put the code. This the AsyncTask class:

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


} 

thanks a lot.

Alex
  • 1
  • 1
    Put the progress dialog showing code in onPreExecute() method and dismissal code in onPostExecute(Void result) method – Jaldip Katre Oct 04 '13 at 11:21

2 Answers2

1

Try this,

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

    }
}
Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
  • Thank for your comment, finally I search this tuto, when you can custom a animation http://karanbalkar.com/2012/10/tutorial-5-custom-progressdialog-with-asynctask/ – Alex Oct 04 '13 at 17:36
0

In here the progress bar is useless so try below linkProgress bar in android

Mohan
  • 311
  • 8
  • 15
  • thanks for the link, but I need use STYLE_SPINNER because I dont know how much time expend. – Alex Oct 04 '13 at 16:06