android 回调机制实例!
详细实现为在类中定义接口。在接口的实现方法中传入參数(也能够不传)。 在调用类中传入新建的接口。并实现未实现的方法。 public class CallBackClass { //传入对应的接口作为參数 public void huidiao(final runDate rundate) { //使用线程取代系统的事件 new Thread() { int i = 0; @Override public void run() { super.run(); while(true) { i++; //传入回调參数 rundate.hui("第" + i + "次回调參数。"); try { sleep(5000); } catch(InterruptedException e) { e.printStackTrace(); } } } }.start(); } //定义接口 public interface runDate { public void hui(String str); } } 在主函数中传入接口參数: public class test { public static vo...