val myadapter = ArrayAdapter.createFromResource(this, R.array.dayfood, android.R.layout.spinner_item)
spinner.adapter = myadapter
我們建立spinner所需要的myadapter
接著將spinner的.adapter方法設置成 剛建立完的myadapter
這樣便完成我們Layout及選項的設置
spinner.onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, pos: Int, id: Long) =
Toast.makeText(this@MainActivity, "今天的午餐就吃" + lunch[pos], Toast.LENGTH_SHORT).show()
override fun onNothingSelected(parent: AdapterView<*>) {}
}