Kev
Kev

Reputation: 173

Android: Progress dialog and toast

Can anyone help me how to put a progress dialog that loads for 5 seconds and shows a fast after? Here's the code:

btnSend.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String phoneNo = editTextRecipient.getText().toString();
                String message = editTextNewMessage.getText().toString();
                setResult(RESULT_OK);
                saveState(phoneNo, message);

                final Toast toast = Toast.makeText(getBaseContext(), 
                         "Your message " + "\"" + message + "\"" + " is sent to " +"\""+ phoneNo+"\"", 
                         Toast.LENGTH_SHORT);
                toast.show();
                Intent setIntent = new Intent(Edit_Message.this, Main.class);
                startActivity(setIntent); 
            }
        });
    }

I want to put a 5 second progress dialog and a tots that prompts that the message has been sent. Can anyone help me?

Upvotes: 0

Views: 3926

Answers (2)

Nikunj Patel
Nikunj Patel

Reputation: 22066

if you really need to make progess bar for 5 second then Progress Dialog & Java thread is use ** Progress dialog**but if you need it to dynamic then AsyncTask is best practice to use. as per your description you need to raise Toast after complete load then you can make it in after complete thread or in asynctask , onPostExecute() will use.

Upvotes: 0

Sandeep Kumar P K
Sandeep Kumar P K

Reputation: 7472

Please try this

showProgress ();
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            dialog.cancel();
            Intent i=new Intent(getApplicationContext(),Main.class);
            startActivity(i);
            finish();

        }
    }, 5000);


private ProgressDialog dialog;
public  void showProgress () {
    dialog = new ProgressDialog(this);
    dialog.setCancelable(true);
    dialog.setMessage("Please wait");
    dialog.show();

}

Upvotes: 1

Related Questions