2016-08-18 98 views
0

嘿,我使用AsynHttpClient。從AsynHttpClient自定義回調

我想在一個Activity中實現我的get和set函數,他們可以被其他人調用。

但是我怎樣才能從響應回調調用我的自定義回調?

我不明白它的內部類是如何工作的

public void requestApiUrl(Callback callback){ 
    JSONObject jsonObj = new JSONObject(); 
    try { 
     jsonObj.put("AppKey",getResources().getString(R.string.AppKey)); 
     AsyncHttpClient client = new AsyncHttpClient(); 
     StringEntity entity = null; 
     try { 
      entity = new StringEntity(jsonObj.toString()); 
      entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); 
      client.get(this, "***************URL***********", entity, "application/json", new JsonHttpResponseHandler() { 
       @Override 
       public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject utils) { 
        super.onSuccess(statusCode, headers, utils); 
        Log.d("HTTP", "response: " + utils.toString()); 
        callback.reponse(); 
       } 

       public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, String responseString, Throwable throwable) { 
        super.onFailure(statusCode, headers, responseString, throwable); 
        Log.d("Failed: ", "" + statusCode); 
        Log.d("Error : ", "" + throwable); 
        callback.reponse(); 
       } 
      }); 

    }catch (JSONException e) { 
     e.printStackTrace(); 
    } 
} 

回答

0

至於我能得到你的問題,你需要調用從子/內部類的功能中的功能屬於父/外班。引用來自this question

答案對於一類

class Outer { 
    void show() { 
     System.out.println("outter show"); 
    } 

    class Inner{ 
     void show() { 
      System.out.println("inner show"); 
        } 
       } 
} 

,你可以簡單地調用

Outer.this.show();