0

I am trying to call a method from getParams() , but nothing happens , is it the right way to call from getParams() or wrong? this method getDrugId(drugNames.get(i)); returns a value , but when i put it inside getparams(); nothing happens.

{
                @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;
    }
NawalSalameh
  • 109
  • 1
  • 13

2 Answers2

0

You're calling the method getDrugId(drugNames.get(i)); without doing anything with the result.

You're probably supposed to use the result as index, like this, right?

            @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;
            }
Pasi Matalamäki
  • 1,843
  • 17
  • 14
0

getDrugId(drugNames.get(i));This is supposed to return some value,right? But you are nowhere assigning the value that the method call is returning you in your code as it looks. Also, could you debug and check what getDrugId(xxx) is returning if you think of utilizing what this method call returns.

robot_alien
  • 955
  • 2
  • 13
  • 30
  • I have debugged the method and it returns a value , but when i put it inside getparams() nothing happenes – NawalSalameh Dec 16 '16 at 12:31
  • You can refer this: http://stackoverflow.com/questions/24285544/android-volley-http-request-custom-header/24402403#24402403 and http://stackoverflow.com/questions/24284651/volley-not-calling-getparams-for-standard-post-request – robot_alien Dec 16 '16 at 13:12