解决方案 »

  1.   

    这是点击时调用的方法:
    private void submit(){
    APIRequest.logStr("提交数据");
    JSONObject json = new JSONObject();
    try {
    json.put("bill_id", id);
    json.put("areas", mAreas);
    json.put("brief", mStr_comment);
    APIRequest.doBillCreateFromVerify(json, new Operater() {

    @Override
    public void OnProcessFinish(JSONObject resultJSON) {
    // TODO
    APIRequest.logStr(resultJSON.toString());
    try {
    boolean isSuccess = resultJSON.getBoolean("success");
    if (isSuccess) {
    Thread.sleep(700);
    Intent intent = new Intent();
    intent.setClass(mContext, WaitQuote.class);
    intent.putExtra("data", resultJSON.getInt("data"));
    startActivity(intent);
    }else {
    Constants.showToast(mContext, resultJSON.getString("message"));
    }
    }
    catch (Exception e) {
    // TODO
    e.printStackTrace();
    }
    }
    });
    }
    catch (JSONException e) {
    // TODO
    e.printStackTrace();
    }
    这是框架里的方法:
    public static void doBillCreateFromVerify(JSONObject json, Operater operater) {
    final Operater mCallBack = operater;
    try {
    json.put("user_id", getUserID());
    }
    catch (Exception e) {
    // TODO: handle exception
    }
    AsyncHttpClient client = new AsyncHttpClient();
    String modeString = "Trade";
    String actString = "createTrade";
    String dataString = json.toString();
    RequestParams params = new RequestParams();
    params.put("model", modeString);
    params.put("action", actString);
    params.put("data", dataString);
    params.put("sign", md5(modeString + actString + dataString + SOME_TEXT));
    client.post(APIURL, params, new JsonHttpResponseHandler() {
    @Override
    public void onSuccess(int statusCode, Header[] headers,
    JSONObject response) {
    super.onSuccess(statusCode, headers, response);
    mCallBack.OnProcessFinish(response);
    } @Override
    public void onFailure(int statusCode, Header[] headers,
    Throwable throwable, JSONObject errorResponse) {
    super.onFailure(statusCode, headers, throwable, errorResponse);
    mCallBack.OnProcessFinish(errorResponse);
    }
    });
    }
    麻烦帮看下、谢谢了