刷新对话框的内容对话框、内容

2023-09-06 17:54:06 作者:壹回身你不在

我需要每当对话框准备DRAWIN更新定制对话框的内容。我不知道这可能是直接刷新或者如果我需要先关闭并重新instatiate呢?

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-instatiate it?

推荐答案

获取该对话框使用和[文章]无效的视图。

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

而不是 Dialog.setContentView的(INT);

做这样的事情:

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();
        }
}