MyDialog.java

//定义一个接口
public interface chuang{
        public void chuang(String string);
    }
    chuang chuang;
    
public MyDialog(@NonNull Context context,chuang chuang) {
    super(context);
    this.chuang=chuang;
    }
    
public void test(){
    chuang.chuang("asd");
 }
MainActivity.java

...
new MyDialog(this, new MyDialog.chuang() {
            @Override
            public void chuang(String string) {
                Log.i("chuang",string);
            }
        }).show();
...
Last modification:October 24th, 2019 at 02:28 pm
如果觉得我的文章对你有用,请随意赞赏