title: Android coding Populate Json Value to Spinner get all values of selected to TextView or Edit
body: <p>Hi Greetings and Salutations. Am trying to develop an android app that during the signup data is fetched from Json stored at the asset folder and populate it in spinner. In the code i have one spinner and multiple EditView and TextView. In the signup the user select country from the spinner and it should automatically set some values to the TextView or EditView like country code, country phone code, id etc but am finding it difficult to do so, have searched but most people only have two value like id and name while mine has more.  The code am modifying i got it somewhere from this site few weeks ago.</p>
  
  <p>i added this to the code </p>
  
  <pre><code>     ArrayList&lt;String&gt; countryName = new ArrayList&lt;String&gt;();
       ArrayList&lt;String&gt; phoneCode = new ArrayList&lt;String&gt;();
       ArrayList&lt;String&gt; countryCode = new ArrayList&lt;String&gt;();
  </code></pre>
  
  <p>and this </p>
  
  <pre><code>   country = jObj.getString("name");
     dial_code = jObj.getString("dial_code");
     country_code = jObj.getString("code");
     countryName.add(country);
     phoneCode.add(dial_code);
     countryCode.add(country_code);
  
      TextCountry = (TextView) findViewById(R.id.country);
      TextDialCode = (TextView) findViewById(R.id.dial_code);
      TextCode = (TextView) findViewById(R.id.code);
  
  
      json_string= loadJSONFromAsset();
  
      ArrayList&lt;String&gt; countryName = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; phoneCode = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; countryCode = new ArrayList&lt;String&gt;();
  
      {
  
          try {
              jsonObj =new JSONObject(json_string);
              jsonArray =jsonObj.getJSONArray("countries");
              String country, dial_code, country_code;
              for (int i = 0; i &lt; jsonArray.length(); i++){
                  JSONObject jObj = jsonArray.getJSONObject(i);
                  country = jObj.getString("name");
                  dial_code = jObj.getString("dial_code");
                  country_code = jObj.getString("code");
                  countryName.add(country);
                  phoneCode.add(dial_code);
                  countryCode.add(country_code);
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
  
      }
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_spinner_dropdown_item, countryName);
  
      spinner = (Spinner)findViewById(R.id.spinner);
      spinner.setOnItemSelectedListener(this);
      spinner.setAdapter(adapter);
  
      //TextDialCode.setText((CharSequence) phoneCode);
  
  
  
  }
  
  public String loadJSONFromAsset() {
      String json = null;
      try {
          InputStream is = getAssets().open("country_phones.json");
          int size = is.available();
          byte[] buffer = new byte[size];
          is.read(buffer);
          is.close();
          json = new String(buffer, "UTF-8");
      } catch (IOException ex) {
          ex.printStackTrace();
          return null;
      }
      return json;
  }
  
  
  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position,
                             long id) {
      Toast.makeText(LoginActivity.this, parent.getItemAtPosition(position).toString() + " Selected" , Toast.LENGTH_LONG).show();
      Country = parent.getItemAtPosition(position).toString();
  
      String Text = String.valueOf(spinner.getSelectedItem());
      String catID = String.valueOf(spinner.getSelectedItemId() + 1);
      Toast.makeText(LoginActivity.this, Text + catID , Toast.LENGTH_LONG).show();
  
      TextDialCode.setText(catID);
  }
  </code></pre>
  
  <p>Some of my Json data</p>
  
  <pre><code>{
      "countries": [
    {
      "name": "Afghanistan",
      "dial_code": "+93",
      "code": "AF"
    },
    {
      "name": "Albania",
      "dial_code": "+355",
      "code": "AL"
    },
    {
      "name": "Algeria",
      "dial_code": "+213",
      "code": "DZ"
    },
    {
      "name": "AmericanSamoa",
      "dial_code": "+1 684",
      "code": "AS"
    },
    {
      "name": "Andorra",
      "dial_code": "+376",
      "code": "AD"
    },
  </code></pre>
  
  <p>Please i will love to know how to set name to TextCountry, code to TextCode and dial_code to TextDialCode.</p>
  
  <p>Thanks</p>