ProgressDialog created from onCreateDialog stops animating on second run

后端 未结 4 1476
情歌与酒
情歌与酒 2021-01-02 22:40

I create a ProgressDialog in onCreateDialog() like so:

protected Dialog onCreateDialog(int id) {
  if (id == DIALOG_PROGRESS_ID)
           


        
4条回答
  •  轮回少年
    2021-01-02 23:29

    I don't like to removeDialog to recreate it on next showing. So, I resolve this issue by using onCreateDialog and onPrepareDialog:

    1) In onCreateDialog I normally create the ProgressDialog. 2) In onPrepareDialog I reference the progressBar inside it and force to restart:

    @Override
    protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
        switch (id){
    
            .....
    
            case DIALOG_PROGRESS_ID:
                ProgressBar p = (ProgressBar) dialog.findViewById(android.R.id.progress);
                p.setVisibility(View.GONE);
                p.setVisibility(View.VISIBLE);
            break;
        }
    }
    

提交回复
热议问题