title: Get spinner selected item id from mysql database
body: <p>I am very new in Android.I want store spinner selected item id, which are saved in mysql database.I already retrieve items from mysql database to my spinner.Now I want to store that spinner selected item id in a global variable.Please help me.
  This is my code</p>
  
  <p><strong>AddProject</strong></p>
  
  <pre><code> RequestQueue requestQueue;
  private ArrayList&lt;Category&gt; categoriesList;
  
  // Url to get all categories
  private String URL_COMPANY = "http://www.mybusket.com/pmsapp/webs/get_all_company.php";
  //Data add
  private String INSERT_URL = "http://192.168.1.9:8082/pmsapp/pmsemp/webapi/project_add.php";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_add_project);
  
      Spinner = (Spinner) findViewById(R.id.spinner);
      ProjectName = (EditText)findViewById(R.id.projectName);
      IsBilling = (EditText)findViewById(R.id.IsBilling);
      BillingBy = (EditText)findViewById(R.id.billingBy);
      ProjectDes = (EditText)findViewById(R.id.projectDescription);
  
      Save = (Button)findViewById(R.id.save);
  
      requestQueue = Volley.newRequestQueue(getApplicationContext());
  
      categoriesList = new ArrayList&lt;Category&gt;();
  
      // spinner item select listener
      Spinner.setOnItemSelectedListener(this);
      new GetCompany().execute();
  
  }
  
  
  /**
   * Adding spinner data
   * */
  private void populateSpinner() {
      List&lt;String&gt; lables = new ArrayList&lt;String&gt;();
  
      for (int i = 0; i &lt; categoriesList.size(); i++) {
          lables.add(categoriesList.get(i).getName());
      }
  
      // Creating adapter for spinner
      ArrayAdapter&lt;String&gt; spinnerAdapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_spinner_item, lables);
  
      // Drop down layout style - list view with radio button
      spinnerAdapter
              .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
      // attaching data adapter to spinner
      Spinner.setAdapter(spinnerAdapter);
  }
  
  private class GetCompany extends AsyncTask&lt;Void, Void, Void&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
      @Override
      protected Void doInBackground(Void... voids) {
  
          ServiceHandler jsonParser = new ServiceHandler();
          String json = jsonParser.makeServiceCall(URL_COMPANY, ServiceHandler.GET);
  
          Log.e("Response: ", "&gt; " + json);
  
          if (json != null) {
  
              try {
                  JSONObject jsonObj = new JSONObject(json);
                  if (jsonObj != null) {
  
                      JSONArray categories = jsonObj.getJSONArray("categories");
                      for (int i = 0; i &lt; categories.length(); i++) {
                          JSONObject catObj = (JSONObject) categories.get(i);
                          Category cat = new Category(catObj.getInt("companyid"),
                                  catObj.getString("companyname"));
  
  
                          categoriesList.add(cat);
                      }
  
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
          }else {
              Log.e("JSON Data", "Didn't receive any data from server!");
          }
  
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
          super.onPostExecute(result);
          populateSpinner();
      }
  }
  
  @Override
  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
      //Toast.makeText(getApplicationContext(), parent.getItemAtPosition(position).toString() + " Selected" , Toast.LENGTH_LONG).show();
  
  }
  </code></pre>
  
  <p>I want to store that company id when a item selected from spinner..Please help me.</p>