我试图从getParams()调用一个方法,但没有任何反应,是从getParams()调用还是错误的正确方法?这个方法getDrugId(drugNames.get(i));
返回一个值,但当我把它放在getparams();没有任何反应。
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
for (int i = 0; i<drugNames.size(); i++){
params.put("drid["+i+"]",getDrugId(drugNames.get(i)));
params.put("paid", 1+"");
}
return params;
}
private String getDrugId(final String drugName) {
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.ROOT + Config.GETRUGSIDS, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
drID=response.trim();
// Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof TimeoutError) {
Toast.makeText(getApplicationContext(), "time out Error", Toast.LENGTH_LONG).show();
} else if (error instanceof NoConnectionError) {
Toast.makeText(getApplicationContext(), "no Connection Error", Toast.LENGTH_LONG).show();
} else if (error instanceof AuthFailureError) {
Toast.makeText(getApplicationContext(), "Authenticatin Failure Error", Toast.LENGTH_LONG).show();
} else if (error instanceof NetworkError) {
Toast.makeText(getApplicationContext(), "Network Error", Toast.LENGTH_LONG).show();
} else if (error instanceof ServerError) {
Toast.makeText(getApplicationContext(), "Server Error", Toast.LENGTH_LONG).show();
} else if (error instanceof ParseError) {
Toast.makeText(getApplicationContext(), "JASON Parse Error", Toast.LENGTH_LONG).show();
}
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("drNAM",drugName);
return params;
}
};
MySingleton.getInstance(getApplicationContext()).addToRequestQueue(stringRequest);
return drID;
}
答案 0 :(得分:0)
您正在调用方法getDrugId(drugNames.get(i));
而不对结果做任何事情。
您可能应该将结果用作索引,就像这样,对吗?
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
for (int i = 0; i<drugNames.size(); i++){
params.put("drid["+getDrugId(drugNames.get(i))+"]",drugNames.get(i));
params.put("paid", 1+"");
}
return params;
}
答案 1 :(得分:0)
getDrugId(drugNames.get(i));
这应该会返回一些价值,对吗?但是你无法分配方法调用在代码中返回的值。此外,如果您考虑使用此方法调用返回的内容,您是否可以调试并检查getDrugId(xxx)
返回的内容。