Hi all

Having a few issues getting a progress dialog to display correctly,
either the app crashes, or the spinner displays indefinitely.


public class Tester extends Activity
{
        /** Called when the activity is first created. */
        private Button OK;
        private Button Cancel;
        private Button Result;
        private Button Exit;

        private EditText EditTextExample;

        public static TextView Label;
        public static TextView Label2;

        private CheckBox check;

        public static int no1;
        public static int no2;
        public ProgressDialog myProgressDialog;
        boolean isRunning = false;

        Handler handler = new Handler(){

        };

        @Override
        public void onCreate(Bundle new)
        {
                super.onCreate(new);
                setContentView(R.layout.amap);

                OK = (Button) findViewById(R.id.OK);
                Cancel = (Button) findViewById(R.id.Cancel);
                Result = (Button) findViewById(R.id.Result);
                Exit = (Button) findViewById(R.id.Exit);

                Label = (TextView) findViewById(R.id.Label);
                Label2 = (TextView) findViewById(R.id.Label2);

                EditTextExample = (EditText) findViewById(R.id.EditTextExample);

                check = (CheckBox) findViewById(R.id.check);

                Cancel.setOnClickListener(CancelListener);
                OK.setOnClickListener(OkListener);
                Exit.setOnClickListener(ExitListener);
                check.setOnClickListener(checkListener);
                Result.setOnClickListener(ResultListener);
        }

        OnClickListener ExitListener = new OnClickListener()
        {
                public void onClick(View v)
                {
                        finish();
                }
        };
        OnClickListener ResultListener = new OnClickListener()
        {
                public void onClick(View v)
                {
                Intent intent = new Intent();
                intent.setClass(Tester.this, Results.class);
                startActivity(intent);
                }
        };




        OnClickListener CancelListener = new OnClickListener()
        {
                public void onClick(View v)
                {
                        EditTextExample.setText("");
                        Label.setText("");
                        Label2.setText("");
                        cCheck.setChecked(false);

                }
        };



        OnClickListener OkListener = new OnClickListener()
        {
                public void onClick(View v)
                {
                        onStart();

                        Thread running = new Thread(new Runnable(){

                        public void run(){


            text  = EditTextExample.getText().toString();

            if(text.length() == 0)
                {
                        Label.setText("No Text!");
                        return;
                }

                else
                {
                         try
                         {

                                 for (int i = no1; i <= no2 ; i++)
                                 {

                                         try
                                         {
                                                 // stuff happens here
                                                 Label.append("Text " + i + " 
Text " + text + "\n" );
                                         }

                             finally
                             {
                                 try
                                 {
                                        //other stuff here
                                 }
                                 catch () {}
                             }
                             handler.sendMessage(handler.obtainMessage());
                                 } //for
                         } //try
                     catch () {}
                }

        }
                        });
                        isRunning = true;
                        running.start();
                }
        };
        public void onStop(){
        super.onStop();
        isRunning=false;
        }

        }


I don't know if that helps at all, but what I would like to do is have
the progress dialog display while the app is going through the For
loop, then stop when it has reached the end. I have tried countless
tutorials and have tried different methods, all of which fail (as in
the example above) any help would be appreciated, or just a point in
the right direction.

Thanks

Jon

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to