Android: Changing Progress Dialog text

眉间皱痕 提交于 2019-12-05 05:10:54

that's working fine:

runOnUiThread(changeText);

with that code:

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

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

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();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!