1

I defines a function in an activity class like this:

private void passParam(String pname){
        StringRequest compareRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        //handle response code
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError arg0) {}
        }) {
            @Override
            protected Map<String, String> getParams() {
                //set post params
                Map<String, String> params = new HashMap<String, String>();
                params.put("foo", "foo");
                params.put("name", pname);//Grammar error, want to use parameter pname 
                return params;
            }
        };

        requestQ.add(compareRequest);
    }

I want to set post parameter "name" value to the parameter pname of function passParam.How to do this conveniently?Thanks!

skfeng
  • 669
  • 2
  • 7
  • 15
  • 1
    Possible duplicate of [how to send json object to server using volley in andorid](http://stackoverflow.com/questions/28344448/how-to-send-json-object-to-server-using-volley-in-andorid) – Pr38y Dec 10 '15 at 11:45
  • 2
    declare String pname as final in the passParam() funtion – Mahesh B ツ Dec 10 '15 at 11:47

0 Answers0