Closing a custom alert dialog on button click

前端 未结 10 1233
灰色年华
灰色年华 2020-12-06 04:01

I\'m having trouble closing my alert dialog. I am using a layout inflator to make the dialog, so I\'m not sure how I would go about closing the thing after I\'m done with it

10条回答
  •  隐瞒了意图╮
    2020-12-06 04:57

         final viewProgressDialogue viewProgressDialogue = new viewProgressDialogue(DebugActivity.this);
            viewProgressDialogue.show();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.d("response","im calling");
                    viewProgressDialogue.dismiss();
                }
            }, 5000);
    
    > Make it one Instance so that it will work
    It Will in the Fragment too.
    
    for Fragment Use
    
        final viewProgressDialogue viewProgressDialogue = new viewProgressDialogue(getActivity());
            viewProgressDialogue.show();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.d("response", "im calling");
                    viewProgressDialogue.dismiss();
                }
            }, 5000);
    
    > viewProgressDialogue Class
    
    public class viewProgressDialogue extends Dialog {
        public viewProgressDialogue(@NonNull Context context) {
            super(context);
    
            WindowManager.LayoutParams wlmp = getWindow().getAttributes();
            getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            wlmp.gravity = Gravity.CENTER_HORIZONTAL;
            getWindow().setAttributes(wlmp);
            setTitle(null);
            setCancelable(false);
            setOnCancelListener(null);
    
            View view = LayoutInflater.from(context).inflate(
                    R.layout.custom_progress, null);
            setContentView(view);
    
    
        }
    }
    

提交回复
热议问题