如何在Kotlin中将逻辑应用于两个微调器

时间:2019-07-20 11:47:43

标签: android

我对微调器有问题,我想要两个微调器的逻辑。例如,一个微调器具有分支,第二个微调器具有学期,我想选择分支然后选择一个学期以在其学期仅打开分支时选择分支吗?



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_syllabus)
        val personNames = arrayOf("Select branch","First Year","IT", "CS", "MECH", "CEVIL", "EXTC")
        val semister = arrayOf("Select Sem","1","2","3","4","5","6","7","8")
        val btn=findViewById<Button>(R.id.btn)
        val spinner = findViewById<Spinner>(R.id.spinner)
        val spinner2=findViewById<Spinner>(R.id.spin2)
        if (spinner != null) {
            val arrayAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, personNames)
            spinner.adapter = arrayAdapter
            spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
                override fun onNothingSelected(parent: AdapterView<*>?) {
                    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.


                }

                override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {

                       btn.setOnClickListener {

                           when (position) {
                               1 -> startActivity(Intent(this@Syllabus, First_year::class.java))


                           }
                       }

                }


            }


        }

    }

0 个答案:

没有答案