我想传递一个请求" _id"在这个" _id"我在点击下面的另一个API后作为回复。
两个API都在同一个Activity中调用。
注意:" _id",我在点击一个API后作为回复,而我想通过" _id"到另一个API。
" _id"得到以下回应: -
{
"success": true,
"count": 3,
"logs": [
{
"_id": 2,
"user": "17",
"__v": 0,
"value": 125,
"unit": "litres",
"savedDT": "2017-03-22T03:44:20.799Z"
},
{
"_id": 0,
"user": "17",
"__v": 0,
"value": 123,
"unit": "ml",
"savedDT": "2017-03-22T03:38:21.142Z"
},
{
"_id": 1,
"user": "17",
"__v": 0,
"value": 123,
"unit": "litres",
"savedDT": "2017-03-22T03:38:21.142Z"
}
]
}
获取回复的代码" _id"
private void getwaterlog(String token) {
// Tag used to the request
String tag_string_req = "req_register";
pDialog.setMessage("Registering ...");
showDialog();
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.WATER_All_LOG_API, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Register Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean success = jObj.getBoolean("success");
if (success) {
String count = jObj.getString("count");
JSONArray jArray = jObj.getJSONArray("logs");
for(int i = 0; i < jArray.length(); i++)
{
JSONObject object = jArray.getJSONObject(i);
String _id = object.getString("_id");
String user = object.getString("user");
String __v = object.getString("__v");
String value = object.getString("value");
String unit = object.getString("unit");
String savedDT = object.getString("savedDT");
}
那我怎么能得到这个&#34; _id&#34;作为对同一活动中另一个API的请求。
我想要这个&#34; _id&#34;在下面的按钮clicklistener: -
btn_water_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = getIntent();
String token = i.getStringExtra("token");
//String "_id" =
deletewater(token,waterId);
}
});
答案 0 :(得分:0)
您可以使用AsynTask使用HttpClient调用api在doInBackground()下发出请求。当收到第一个请求响应时,再发出第二个请求并获得响应