Refresh contents of dialog

后端 未结 2 457
孤街浪徒
孤街浪徒 2021-01-15 16:10

I need to update a custom dialog content whenever that dialog is ready to be drawin. I am not sure this could be refreshed directly or if I need to close it first and re-ins

2条回答
  •  暖寄归人
    2021-01-15 16:33

    Get the view that the Dialog is using and [post]invalidate it.

    Instead of Dialog.setContentView(int);

    Do something like:

    public class MyDialog {
            View v = null;
    
            public Dialog show(Context context) {
                Dialog d = new Dialog(context);
                v = LayoutInflater.from(context).inflate(R.layout.resource, null);
                d.setContentView(v);
                return d.show();
            }
    
            public void update() {
                v.invalidate();
            }
    }
    

提交回复
热议问题