接著昨天的程式碼
when (position) {
0 -> {
val view = inflater.inflate(R.layout.fragment_1, container, false)
val btn_contact = view.findViewById<Button>(R.id.btn_contact)
val textView3= view.findViewById<TextView>(R.id.textView3)
btn_contact.setOnClickListener {
//textView.text="ABC"
AlertDialog.Builder(this.context)
.setTitle("聯繫方式")
.setMessage("我的信箱:409570157@gapp.fju.edu.tw ")
.setPositiveButton("確認"){dialog, _ ->
dialog.dismiss()
}
.show()
parentFragmentManager.setFragmentResultListener("freg2",this){
freg2,bundle-> textView3.text = bundle.getString("mainMeal")
}
}
return view
}
1 -> {
val view = inflater.inflate(R.layout.fragment_2, container, false)
val send = view.findViewById<Button>(R.id.send)
val mealA: CheckBox = view.findViewById(R.id.checkBox)
val mealB: CheckBox = view.findViewById(R.id.checkBox2)
val mealC: CheckBox = view.findViewById(R.id.checkBox3)
val mealD: CheckBox = view.findViewById(R.id.checkBox4)
send.setOnClickListener {
//3.1 判斷哪個check buton被勾選(可複選)
val meal1 = if (mealA.isChecked) "A餐" else ""
val meal2 = if (mealB.isChecked) "B餐" else ""
val meal3 = if (mealC.isChecked) "C餐" else ""
val meal4 = if (mealD.isChecked) "D餐" else ""
val meal = "$meal1 $meal2 $meal3 $meal4"
//3.2 將點餐項目存入bundle
val bundle = Bundle()
bundle.putString("mainMeal", meal)
//3.3 透過setResult將資料回傳呼叫頁(主頁)
parentFragmentManager.setFragmentResult("freg2",bundle)
}
return view
}
else -> {
val view = inflater.inflate(R.layout.fragment_3, container, false)
return view
}
}
}
那Android Studio 就到這邊啦~
明天要講甚麼呢?
敬請期待
結果我還是躲不過確診風波
確了......