Bart Bart -4 years ago 105
Android Question

Parsing simple json to spinner entries

I've been trying to get into android/java programming and I've been having issues understanding how to properly get the value of this json and parse it into the options to select in a spinner.

My json is like:


My current code is like:

protected void onCreate(Bundle savedInstanceState) {

RequestQueue queue = Volley.newRequestQueue(this);
String url = "";

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,new Response.Listener<String>() {
public void onResponse(String response) {
//Do something with response
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {


What would be the easiest way to get these values (Result1, Result2, Result3, etc.) into the spinner.entries?

Thanks in advance

Answer Source

Try this:


List<String> myList = new ArrayList<String>(Arrays.asList(s.split("\",\"")));

ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(varRoot, android.R.layout.simple_spinner_item, myList);

spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down vieww

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download