Code example for ProgressDialog

Methods: setIndeterminatesetMessage, dismiss, isIndeterminate, setOnCancelListener, show

0
    public void handleMessage(Message msg)
    { 
        switch (msg.what) {
            case STATUS_FETCHING_INFO:
                ensureDialog(true); 
                mDialog.setMessage("Connecting...");
 
            case STATUS_FETCHING_PLAYLISTS:
                ensureDialog(true); 
                mDialog.setMessage("Fetching playlists...");
                break; 
 
            case STATUS_FETCHING_SONGS:
                ensureDialog(true); 
                mDialog.setMessage("Fetching songs...");
                break; 
 
            case STATUS_IMPORTING_SONGS:
                Integer progress = (Integer) msg.obj;
                ensureDialog(false); 
                mDialog.setMessage("Importing songs...");
                mDialog.setMax(mPlaylist.getCount());
                mDialog.setProgress(progress);
                break; 
 
            case STATUS_FINISHED:
                if (mDialog != null)
                    mDialog.dismiss();
                mListener.onFinish();
                break; 
                 
            case STATUS_ERROR:
                Exception err = (Exception) msg.obj;
                showError(err);
                break; 
        } 
    } 
 
    private void ensureDialog (boolean indeterminate)
    { 
        if (mDialog == null || mDialog.isIndeterminate() != indeterminate) {
            if (mDialog != null)
                mDialog.dismiss();
 
            mDialog = new ProgressDialog(mActivity);
            mDialog.setOnCancelListener(mCancelListener);
            mDialog.setIndeterminate(indeterminate);
 
            if (!indeterminate)
                mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
 
            mDialog.show();
        } 
    } 
 
    private void showError (Exception ex)
    {