0

I am making a Android app and I am populating a spinner from a web service, the response looks like this this:

[  
   {  
      "Text":"Business Critical",
      "Value":"3"
   },
   {  
      "Text":"Business Urgent",
      "Value":"4"
   },
   {  
      "Text":"User Urgent",
      "Value":"5"
   },
   {  
      "Text":"Normal",
      "Value":"6"
   },
   {  
      "Text":"Low",
      "Value":"7"
   }
]

I am making a second request to get the ticket details which looks like this:

{  
   "AssignedTo":"John Doe",
   "Id":33258,
   "Priority":"Low",
}

I am setting the "Id" and "AssignedTo" in EditText boxes like so:

StringRequest myTicketRequest = new StringRequest(Request.Method.GET, ticketDetailUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try{
                    JSONObject ticket = new JSONObject(response);
                    if(ticket.has("Subject"))
                        assignedTxt.setText(ticket.getString("AssignedTo"));
                    if(ticket.has("Description"))
                        idTxt.setText(ticket.getString("Id"));

                    //Set Category here


                }catch (JSONException e){e.printStackTrace();}

So my question is how do I set the spinner to the "Priority" in my second request which is equal to "Low" in the spinner?

Thanks in advance.

Adam Lee
  • 66
  • 1
  • 15
  • What do you mean by setting the spinner to the "Priority"? – Juan Feb 13 '18 at 23:21
  • I think I need to use something like setSelection(); but I am not sure. The spinner has five options and I need it to set the selected item based on the Priority value from the second response. – Adam Lee Feb 13 '18 at 23:38
  • Is it this you need https://stackoverflow.com/questions/11072576/set-selected-item-of-spinner-programmatically? – Juan Feb 13 '18 at 23:46
  • I have tried all of those answers with no luck. Thanks for your help though. – Adam Lee Feb 13 '18 at 23:48
  • Yes, I have found the answer from the link you provided thanks a lot. – Adam Lee Feb 13 '18 at 23:58

0 Answers0