1.定义接口
View Code
/** * @author zhou * */ public interface CallBack { public void tellSomeOne(String str); }
2.定义工具类
View Code
public class Tools{ public String aaa=""; public void doSomeSth() { aaa = "asdasda"; } public void CallSomeOne(CallBack call) { aaa="a1111111111111111111"; call.tellSomeOne(aaa); } }
3.调用工具类
View Code
private void initView() { // TODO Auto-generated method stub btnConn =(Button)findViewById(R.id.btnConn); btnConn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Tools tool = new Tools(); tool.doSomeSth(); tool.CallSomeOne(new CallBack() { @Override public void tellSomeOne(String str) { // TODO Auto-generated method stub Toast.makeText(HttpAdapatorSerActivity.this, str, Toast.LENGTH_LONG).show(); } }); } }); }
参考:http://blog.163.com/zhou_411424/blog/static/197362156201251114740616/ 谢谢原作者