Android: Changing Progress Dialog text

19,942

Solution 1

that's working fine:

runOnUiThread(changeText);

with that code:

private Runnable changeText = new Runnable() {
    @Override
    public void run() {
        m_ProgressDialog.setMessage(myText);
    }
};

Solution 2

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();
            }       
        }   
    }
Share:
19,942
iGio90
Author by

iGio90

Updated on June 15, 2022

Comments

  • iGio90
    iGio90 almost 2 years

    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

  • jlopez
    jlopez over 9 years
    i'm glad to help you :)
  • Adnan Ali
    Adnan Ali almost 8 years
    Always show the reference where you copied from stackoverflow.com/questions/3947080/…