Android: Changing Progress Dialog text
Asked Answered
C

2

7

is it possible to change the progressDialog text?

my code:

progressDialog = ProgressDialog.show(BackupActivity.this, "In progress", "test1");
                            new Thread() {
                                public void run() {
                                    try{
                                        sleep(10000);
                                            } catch (Exception e) {
                                                Log.e("tag", e.getMessage());
                                            } progressDialog.dismiss();
                                }
                            }.start();
                        }
                    });
                    selectExportsDialog = builder.create();
                }
                selectExportsDialog.show();
                break;          }

I would like to change test1 to test2 after example 10 seconds. Possible?

Thanks

Ceciliacecilio answered 6/2, 2013 at 10:54 Comment(0)
D
3

You can try this:

private class ProgressRunner extends AsyncTask<URL, Integer, Long>
    {
        protected void onPreExecute()
        {
            try    
            {
                dialog = new ProgressDialog(context);
                dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                dialog.setTitle("TITLE");
                dialog.setMessage("MY TEXT 1");
                dialog.setCancelable(false);
                dialog.setProgress(0);              
                dialog.setIndeterminate(false);
                dialog.show();              
            } 
            catch (Exception e)
            {               
                e.printStackTrace();
                dialog.dismiss();
            }
        }


        @Override
        protected void onCancelled() 
        {
            super.onCancelled();
            dialog.dismiss();           
        }


        @Override
        protected Long doInBackground(URL... params) 
        {   
            // process the code here
            dialog.setMessage("MY TEXT 2");
            return null;
        }

        protected void onProgressUpdate(Integer... progress)
        {           
            dialog.setProgress(progress[0]);
        }       

        protected void onPostExecute(Long result)
        {
            try 
            {                               
                dialog.dismiss();           

            } 
            catch (Exception e) 
            {               
                e.printStackTrace();
                finish();
            }       
        }   
    }
Demodulate answered 6/2, 2013 at 11:5 Comment(0)
P
0

Use setTitle and setMessage methods

Source Tutorial

// Method to show Progress bar
private void showProgressDialogWithTitle(String title,String substring) {
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    //Without this user can hide loader by tapping outside screen
    progressDialog.setCancelable(false);
    //Setting Title
    progressDialog.setTitle(title);
    progressDialog.setMessage(substring);
    progressDialog.show();

}

// Method to hide/ dismiss Progress bar
private void hideProgressDialogWithTitle() {
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.dismiss();
}
Pratincole answered 16/8, 2018 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.