public interface CountInterface {
public void CountValue(String value);
}
2、写一个Test类:
public class Test {
int countsum;
private CountInterface countcallback;
public void setCallBack(int x, int y, CountInterface countcallback) {
this.countcallback = countcallback;
countsum = x + y;
}
public void count() {
countcallback.CountValue(countsum + "");
}
}
3、MainActivity类onCreate()函数下:
Test test = new Test();
test.setCallBack(2, 5, new CountInterface() {
//回调函数
@Override
public void CountValue(String value) {
System.out.println("回调函数中的值:" + value );
}
});
//执行下面的代码才会执行回调函数中的代码
test.count();
1、写一个接口:public interface CountInterface { public void CountValue(String value);}2、写一个Test类:public class Test { int countsum; private CountInterface countcallback; public vo