Android Progress Dialog Spinner没有显示

时间:2015-08-20 10:37:57

标签: android spinner progressdialog

我为Progress Dialog创建了一个类,以避免重写几行代码。请检查以下代码。

backends/default/views.py

这就是我在片段中使用它的方式:

public class AppProgressDialog {

/**
 * progress dialog object 
 */
private ProgressDialog progressDialog;

/**
 * stores is progress dialog is cancellable 
 */
private boolean isProgressDialogCancelable = false;

/**
 * style of progress dialog
 */
private int progressDialogStyle = ProgressDialog.STYLE_SPINNER;

/**
 * true if progress time not known
 */
private boolean isIndetermined = true;

/**
 * constructor to initialize this custom progress dialog class
 * @param activity activity to which this progress dialog will belong
 * @param message Message to be shown inside progress dialog
 */
public AppProgressDialog(Activity activity) {
    progressDialog = new ProgressDialog(activity);
    progressDialog.setCancelable(isProgressDialogCancelable);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setIndeterminate(isIndetermined);
}

/**
 * function to set display message inside progress dialog
 * @param message string to be shown inside progress dialog 
 */
public void setProgressDialogMessage(String message)
{
    if (progressDialog!=null) {
        progressDialog.setMessage(message);
    }
}

/**
 * function to show progress dialog
 */
public void showProgressDialog()
{
    if (progressDialog!=null) {
        if(!progressDialog.isShowing())
            progressDialog.show();
    }
}

/**
 * function to hide progress dialog
 */
public void dismissProgressDialog()
{
    if (progressDialog!=null) {
        if(progressDialog.isShowing())
            progressDialog.hide();
    }
}

}

现在,问题是我无法看到通常在进度对话框中看到的微调器。我在Lollipop上测试了这个。

1 个答案:

答案 0 :(得分:0)

你需要在UI线程中运行进度对话框,所以在你的AsyncTask preExecute方法中,如下所示,

getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                    progressDialog = new AppProgressDialog(getActivity());
                    progressDialog.setProgressDialogMessage("Logging you to eventizon");
                    progressDialog.showProgressDialog();
                    }
                });

和onPostExecute关闭对话框。