title: Android: Get Spinner data to string
body: <p>I want to get spinner value to string. I have used custom spinner adapter to add data from json and data load to spinner successfully but I am  unable to get loaded data
  to string.</p>
  
  <pre><code>public class RegisterActivity extends Activity { 
      private Spinner sprCity;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_register);
  
          getId();
          addSpinnerData();
          setListner();   
      }
      private void getId() 
      {
          sprCity = (Spinner) findViewById(R.id.sprCity);
      }
      private void setListner() {
              sprCity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                  @Override
                  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                      String text= parent.getItemAtPosition(position).toString() ;
                      Log.e("Spinner detail ","&gt;&gt;&gt;&gt;&gt;&gt;"+text);
                  }
                  @Override
                  public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
                  }
              });
      }
      private void addSpinnerData() {
      JSONArray cityArray = object.getJSONArray(WebField.ZIP_DETAIL.RESPONSE_ARRAY_CITY_LIST);
      for (int i = 0; i &lt; cityArray.length(); i++) 
      {
          getZipDetailModel = new GetZipDetailModel();
          JSONObject object1 = cityArray.getJSONObject(i);
          Log.e("Checking ojbect1", "******" + object1);
          strGetCity = object1.getString(WebField.ZIP_DETAIL.RESPONSE_OBJECT_CITY_NAME);
          getZipDetailModel.setStrCity(object1.getString(WebField.ZIP_DETAIL.RESPONSE_OBJECT_CITY_NAME));
          alZilcode.add(getZipDetailModel);
          myAdapter = new MyAdapter(RegisterActivity.this, alZilcode);
      }
          sprCity.setAdapter(myAdapter);
          myAdapter.notifyDataSetChanged();       
      }
  }
  </code></pre>
  
  <p>Here is my custom Spinner Adapter.</p>
  
  <pre><code>        public class MyAdapter extends BaseAdapter{
      private Context context;
      private static LayoutInflater inflater;
      private ArrayList&lt;GetZipDetailModel&gt; objects;
      public MyAdapter(Context context, ArrayList&lt;GetZipDetailModel&gt; p1) {
  
          this.context = context;
          this.objects = p1;
      }
      @Override
      public int getCount() {
          return objects.size();
      }
      @Override
      public Object getItem(int position) {
          return position;
      }
      @Override
      public long getItemId(int position) {
          return position;
      }
      class Holder
      {
          TextView lable;
      }
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View myView = null;
          try {
              Holder holder;
              myView = convertView;
              if (myView == null) {
                  inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  myView = inflater.inflate(R.layout.adapter_city, null);
                  holder = new Holder();
                  holder.lable= (TextView) myView.findViewById(R.id.tvCityName);
                  myView.setTag(holder);
              }
              else {
  
                  holder = (Holder) myView.getTag();
              }
              holder.lable.setText(objects.get(position).getStrCity());
          } catch (Exception e) {
              e.printStackTrace();
          }
          return myView;
      }
  }
  </code></pre>
  
  <p>here is my model class.</p>
  
  <pre><code>    public class GetZipDetailModel {
      private String strCity,strState,strCountry;
      public String getStrCity() {
          return strCity;
      }
      public void setStrCity(String strCity) {
          this.strCity = strCity;
      }
      public String getStrState() {
          return strState;
      }
      public void setStrState(String strState) {
          this.strState = strState;
      }
      public String getStrCountry() {
          return strCountry;
      }
      public void setStrCountry(String strCountry) {
          this.strCountry = strCountry;
      }
  }
  </code></pre>