Search Unity

Fill Dropdown programatically -> not shows all entries by scrolling bottom | Unity 5.4.0f3

Discussion in 'Scripting' started by mikolo, Mar 22, 2017.

  1. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    Hello,

    i fill a dropdown with dynaic content from json and it does not show all entries? How can i fix that?
    Attached the screenshots where you can see that tehere are more entries and here is the code:
    Code (CSharp):
    1.  
    2. /// <summary>
    3.     /// Setups the country dropdown.
    4.     /// </summary>
    5.     private void SetupCityDropdown( JsonData data ) {
    6.  
    7.         DropdownCities.gameObject.SetActive (true);
    8.  
    9.         DropdownCities.options.Clear();
    10.  
    11.         List <City> tmp_city_data = new List<City> ();
    12.         city_data = new List<City> ();
    13.  
    14.         City start_select = new City();
    15.         start_select.Postalcode = "nothing_selected";
    16.         start_select.PlaceName = "Bitte wählen...";
    17.  
    18.         for (int i = 0; i < data["all_cities"].Count; i++)
    19.         {
    20.             Debug.Log("placeName= "+ data["all_cities"][i]["placeName"]);
    21.  
    22.             City newCity = new City ();
    23.             newCity.ID = i;
    24.  
    25.             newCity.CountryCode = data ["all_cities"] [i] ["countryCode"].ToString();
    26.             newCity.PlaceName = data ["all_cities"] [i] ["placeName"].ToString();
    27.             newCity.Postalcode = data ["all_cities"] [i] ["postalcode"].ToString();
    28.  
    29.             newCity.Lng = float.Parse(data ["all_cities"] [i] ["lng"].ToString());
    30.             newCity.Lat = float.Parse(data ["all_cities"] [i] ["lat"].ToString());
    31.  
    32.             tmp_city_data.Add (newCity);
    33.         }
    34.  
    35.         //sort list by ??
    36.         city_data = tmp_city_data.OrderBy(o=>o.PlaceName).ToList();
    37.  
    38.         city_data.Insert(0, start_select);
    39.  
    40.         //write to DropdownCountry
    41.         int counter = 0;
    42.         foreach(City city in city_data)
    43.         {
    44.             if (counter > 0) {
    45.                 DropdownCities.options.Add(new Dropdown.OptionData(city.Postalcode + ", " +city.PlaceName));
    46.             }
    47.             counter++;
    48.         }
    49.  
    50.         LabelDropDownCities.text = city_data [1].PlaceName;
    51.         DropdownCities.GetComponent<Dropdown> ().value = 1;
    52.  
    53.         pageViewController.hideLoading ();
    54.  
    55.         DropdownCities.Show ();
    56.     }
    Bildschirmfoto 2017-03-22 um 06.41.50.png Bildschirmfoto 2017-03-22 um 06.42.15.png
     

    Attached Files:

  2. jackishere

    jackishere

    Joined:
    Mar 1, 2014
    Posts:
    22
    try use default scroll bar, see if the problem still persist?