Tyr*_*ter 3 java android function callback dynamicmethod
我正在创建此方法/函数,我需要实现回调.我的意思是,我需要添加一个动态参数,一个函数.我读过几篇文章但我无法理解如何获得它.任何想法或使用的例子?
public void httpReq (final String url, final Object postData, String callbackFunct, Object callbackParam,String callbackFailFunct) {
if (postData == null || postData == "") {
//GET
Thread testGET = new Thread(new Runnable() {
@Override
public void run() {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
....
}
}
} else {
//POST
Thread testPOST = new Thread(new Runnable() {
@Override
public void run() {
HttpGet httpPost = new HttpPost(url);
....
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Bla*_*elt 15
定义您的界面:
public interface MyInterface {
public void myMethod();
}
Run Code Online (Sandbox Code Playgroud)
将其添加为方法的参数
public void httpReq (final String url, final Object postData, String callbackFunct, Object callbackParam,String callbackFailFunct, MyInterface myInterface) {
// when the condition happens you can call myInterface.myMethod();
}
Run Code Online (Sandbox Code Playgroud)
例如,当你打电话给你的方法时,
myObjec.httpReq(url, postData, callbackFunct, callbackParam, callbackFailFunct,
new MyInterface() {
@Override
public void myMethod() {
}
});
Run Code Online (Sandbox Code Playgroud)
那是你需要的吗?
归档时间: |
|
查看次数: |
6582 次 |
最近记录: |