【发布时间】:2019-03-14 06:41:20
【问题描述】:
从活动中使用 onClick 侦听器调用意图不是问题,但片段中的相同代码会在 Intent 中引发不可修复的代码错误,表示无法使用这些参数调用其构造函数。这是我的代码:
类 FragEqCrew : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.frag_eq_crew, container, false)
eq_row.setOnClickListener(({
var clickintent = Intent(this@FragEqCrew, Equipment::class.java)
startActivity(clickintent)
}))
}
}
【问题讨论】:
-
因为片段不是上下文。使用
getActivity() -
Harpreet Singh 的评论是解决方案。谢谢。
标签: android android-intent kotlin fragment onclicklistener