Spinner Widget

PHOTO EMBED

Thu Apr 14 2022 19:12:38 GMT+0000 (UTC)

Saved by @anasrathore #kotlin

private val genderArr = arrayOf("Select Gender","Male","Female","Other")
setGenderDropDown()

 private fun setGenderDropDown(){
        //val adapter = ArrayAdapter.createFromResource(this, R.array.gender_array, android.R.layout.simple_dropdown_item_1line)
        val adapter = ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, genderArr)
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        spGender.adapter = adapter

        spGender.onItemSelectedListener = this
    }

//XML

        <Spinner
            android:id="@+id/spGender"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@drawable/bg_editbox"/>
content_copyCOPY