Android:更改进度对话框文本

时间:2013-02-06 10:54:17

标签: android dialog textview progressdialog

是否可以更改progressDialog文本?

我的代码:

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

我想在示例10秒后将test1更改为test2。可能的?

由于

3 个答案:

答案 0 :(得分:10)

工作正常:

runOnUiThread(changeText);

使用该代码:

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

答案 1 :(得分:4)

你可以试试这个:

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

答案 2 :(得分:0)

使用 setTitle setMessage 方法

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