【发布时间】:2022-01-16 14:56:05
【问题描述】:
我尝试在 Android Studios 中制作秒表。我知道如何在活动上进行,但我需要在片段上进行。我的问题是我不知道如何在带有绑定的片段中设置内容视图。
相关代码:
class Stoppuhr : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_stoppuhr, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = FragmentStoppuhrBinding.inflate(layoutInflater)
setContentView(binding.root)//<---
binding.startStopButton.setOnClickListener { startStopTimer() }
binding.resetButton.setOnClickListener { resetTimer() }
serviceIntent = Intent(getActivity(), TimerService::class.java)
requireActivity().registerReceiver(updateTime, IntentFilter(TimerService.TIMER_UPDATED));
}}
提前致谢。
【问题讨论】:
标签: android kotlin binding fragment setcontentview