0

I test my spinner in real device SM-G900F API 23, it is working well. But it is not working in SM-N9005 API 21. It shows the spinner but it did not show any options when I click the spinner.

Please see my code below and help to solve this issue.

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_country_selector)

        val spinnerOne = search_spinner1
        val spinnerTwo = search_spinner2
        val userDetail = UserDetail(this)
        //SpinnerOne
        spinnerOne.adapter = ArrayAdapter<String>(this, R.layout.item, countryArray)
        //SpinnerTwo
        val dataAdapter = ArrayAdapter<String>(this, R.layout.item, tempArray)
        spinnerTwo.setAdapter(dataAdapter)
        spinnerOne.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
            override fun onNothingSelected(parent: AdapterView<*>?) {
            }
            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
                countrySelected = parent?.getItemAtPosition(position).toString()
                citySelected = countrySelected
                if (countrySelected == "香港") {
                    userDetail.saveCountry(countrySelected)
                    userDetail.saveCity(countrySelected)
                    spinnerTwo.visibility = View.GONE
                    finish()
                } else if (countrySelected == "澳門") {
                    userDetail.saveCountry(countrySelected)
                    userDetail.saveCity(countrySelected)
                    spinnerTwo.visibility = View.GONE
                    finish()
                } else if (countrySelected == "台灣") {
                    userDetail.saveCountry(countrySelected)
                    tempArray.clear()
                    tempArray.addAll(taiwanArray)
                    dataAdapter.notifyDataSetChanged()
                    spinnerTwo.visibility = View.VISIBLE
                } 
            }
        }

        //hide spinner2
        spinnerTwo.visibility = View.GONE
        spinnerTwo.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
            override fun onNothingSelected(parent: AdapterView<*>?) {
            }
            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
                citySelected = parent?.getItemAtPosition(position).toString()
                if (citySelected == "選擇城市") {
                } else {
                    userDetail.saveCity(citySelected)
                    finish()
                }
            }
        }

Here with the xml file: enter image description here

enter image description here

enter image description here enter code here

GPH
  • 1,111
  • 6
  • 29
  • 49
  • both spinners have the same problem? –  Jul 24 '18 at 10:08
  • 2nd spinner will not show, if 1st spinner option not selected. – GPH Jul 24 '18 at 10:09
  • In the image you provided there is no spinner or arrow button at the end to press for it to expand. Do you really see the spinner? –  Jul 24 '18 at 10:12

1 Answers1

0

I found the answer

android:spinnerMode="dialog"

add this code it will be work for API 21 and 23

GPH
  • 1,111
  • 6
  • 29
  • 49