//定义回调:
MyCallBackListener mMyCallBackListener;
public void setMyCallBackListener(MyCallBackListener mMyCallBackListener) {
this.mMyCallBackListener = mMyCallBackListener;
}
public void useCallBackMethod() {
mMyCallBackListener.callBackMethod(num);
}
interface MyCallBackListener {
void callBackMethod(int i);
}
//使用回调:
public class TwoActivity extends ActionBarActivity implements
MyCallBackListener {
MainActivity mm = new MainActivity();
mm.setMyCallBackListener(TwoActivity.this);
mm.useCallBackMethod();
@Override
public void callBackMethod(int i) {
// TODO Auto-generated method stub
Log.i("yqftest", "callBackMethod == " + i);
}
//Java 回调函数:
package com.yqf;
public class Button {
OnclickListener mOnclickListener;
public void setOnclickListener(OnclickListener mOnclickListener) {
this.mOnclickListener = mOnclickListener;
}
public void clickDown() {
mOnclickListener.OnClick(10);
}
interface OnclickListener {
void OnClick(int i);
}
}
package com.yqf;
import com.yqf.Button.OnclickListener;
public class Mine implements OnclickListener {
@Override
public void OnClick(int i) {
// TODO Auto-generated method stub
System.out.println(i);
}
}
package com.yqf;
public class Main {
public static void main(String[] args) {
Button btn = new Button();
btn.setOnclickListener(new Mine());
//通过Button的方法clickDown(),回调自己的方法OnClick(int i)
btn.clickDown();
}
}
MyCallBackListener mMyCallBackListener;
public void setMyCallBackListener(MyCallBackListener mMyCallBackListener) {
this.mMyCallBackListener = mMyCallBackListener;
}
public void useCallBackMethod() {
mMyCallBackListener.callBackMethod(num);
}
interface MyCallBackListener {
void callBackMethod(int i);
}
//使用回调:
public class TwoActivity extends ActionBarActivity implements
MyCallBackListener {
MainActivity mm = new MainActivity();
mm.setMyCallBackListener(TwoActivity.this);
mm.useCallBackMethod();
@Override
public void callBackMethod(int i) {
// TODO Auto-generated method stub
Log.i("yqftest", "callBackMethod == " + i);
}
//Java 回调函数:
package com.yqf;
public class Button {
OnclickListener mOnclickListener;
public void setOnclickListener(OnclickListener mOnclickListener) {
this.mOnclickListener = mOnclickListener;
}
public void clickDown() {
mOnclickListener.OnClick(10);
}
interface OnclickListener {
void OnClick(int i);
}
}
package com.yqf;
import com.yqf.Button.OnclickListener;
public class Mine implements OnclickListener {
@Override
public void OnClick(int i) {
// TODO Auto-generated method stub
System.out.println(i);
}
}
package com.yqf;
public class Main {
public static void main(String[] args) {
Button btn = new Button();
btn.setOnclickListener(new Mine());
//通过Button的方法clickDown(),回调自己的方法OnClick(int i)
btn.clickDown();
}
}