Android Spinner Example to Load JSON using Volley

In this tutorial we will create an Android Spinner Example Application. So the first thing probably you are thinking is What is SpinnerActually Spinner is used to show a dropdown list. So in this Android Spinner Example Tutorial we will create a spinner. And in the spinner we will show the values from MySQL database.

Android Spinner Example Video

Before going further you can check out this video to see the final output of the app we are creating.

Now if you wanna create the same, lets begin this Android Spinner Example Tutorial. So in this tutorial we will retrieve data from our webserver using JSON String. I have my URL that will give me a JSON string by fetching values from MySQL database.

The above link will give us the following json string.

You can create your own url or you can also use mine. Lets move to Android Studio now.

Creating Android Spinner Example Application

  • Open Android Studio and create new Project.
  • For this tutorial we will use volley library so add the following code in you build.gradle dependencies

  • Now sync your project with gradle.
  • Come to activity_main.xml and create the following layout.
android spinner example layout
Android Spinner Example Layout
  • In the above layout we have a Spinner and 3 TextViews. When user will select an item from the Spinner the details will be shown to the TextView.
  • You can use the following xml code for creating the above layout. Define Spinner and 3 TextViews.

  • Create a class named and write the following code.

  • Now come to and write the following code.

  • Finally before running this Android Spinner Example , add internet permission to your manifest file.

  • Now run your application.
android spinner example
Android Spinner Example Application
  • Bingo! Our Android Spinner Example App is working absolutely fine. You can also download my source code from below.

Get source of Android Spinner Example

So thats all for this Android Spinner Example Tutorial friend. This was a very simple android spinner example. Please do comment if you are having any trouble or queries. Thank You 🙂

56 thoughts on “Android Spinner Example to Load JSON using Volley”

    • Nice example,
      But in my code i need to load first spinner with name of city and when ever i click on city i need to load another spinner w.r.t city id . can help me in two spinners?


      • I have same problem with you. and how to get String from OnItemSelected position so I can implement it on other method to load other JSON. Untill now I just can get string with “Textview.setText(getName(position))” and to get String on another method I use “String name = Textview.getText().toString()”. Anyone can help me to get String without implement it to Textview?

  1. I think it’s great your tutorial, and I give many thanks , but , you could explain how this Json to have several lines in the table? Thanks for your answer.

    [{“Username”:”Bayarri Carmona,Alex”,
    “Course”:{“Session”:”2″, “Name”:”0″}},

    {“Username”:”Borras Vicent,Antonio Salvador”,
    “Course”:{“Session”:”0″, “Name”:”0″}}]}

  2. Thank you for this tutorial,
    Have you any tutorial or example,i need onclick on spinner item to show result into a listview passing the id from the spinner to the listview?
    can anyone help me?

  3. belal i want php script for change pswd+android code using volley only…..
    I done login and registration task using androidhive example… your will be important…..

  4. hi… will u plzz help me… i am using a viewpager and feeding data through json parsing using volley.. I am doing this using a fragment and adapter..My volley response code is in the fragment.. can u help me to define the spinner in the fragment..?? plzz help

  5. hello Belal,

    thank you for this tutorial.
    i got the spinner working with my code , yet i need the item selected from the spinner to be stored in an edit text field instead of a text view and that is to use it later to submit its value to Server .
    my problem is that i am facing a difficulty in having the edit text field empty by default . it always contain the first spinner item in it

    how can i solve that
    thank you in advance

  6. I have 2 spinner. How can i implement with 2 spinner ? so should i do getData1() and getStudents1()…??? please reply buddy 🙂

  7. Well Explained I just Tried and Its working smoothly after troubleshoot some bugs .But I want to maintain the last selected value in spinner after starting the app instead of selecting again and again Can any one suggest what need to do .

  8. Heyy Thank you so much for this tutorial it’s really helpful sir but i want to have a listview of that if you can do a tutorial about that it will be so helpful for me for example if we have different student with the same username i want to list me students Pleaaase sir !!thanks in advance

  9. belal how i can load data in listview based spinner clicked id…. i have tried but getting error….. will you guide me??

  10. how to get data from mysql data in spinner and get data separately for every item of spinner from mysql data in to listView using CodeIgnither framework instead of php script


  11. 11-25 16:25:00.088 2115-2115/net.simplifiedcoding.spinnerexample W/System.err: org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
    11-25 16:25:00.089 2115-2115/net.simplifiedcoding.spinnerexample W/System.err: at org.json.JSON.typeMismatch(

    how to resolve this

  12. could give a tutorial when selecting items in the spinner, the new data will appear in a second spinner, a spinner with parameters. Thank you

  13. How to implement when no array name in json sting

    “name”:”Faiz Khan”,
    “name”:”Belal Khan”,

  14. Very nice guide. But when I am trying to implement this in a fragment, the data is downloading but not showing in spinner by default. When clicking the spinner the list shows, but the spinner click listener doesn’t work as well. Any guide to point me would be very helpful.

  15. hallo belal
    your tutorial is very easy to understand
    but when I try I get an error in this section
    RequestQueue requestQueue = Volley.newRequestQueue (this);

    in part (this) is red. how do i solve it?


Leave a Comment