我通过构建应用程序来学习Kotlin,现在,我正在尝试为RecyclerView创建适配器。但是,我为ViewGroup选择的名称标记为class RecyclerAdapter: RecyclerView.Adapter<RecyclerAdapter.PosterHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getItemCount(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onBindViewHolder(holder: RecyclerAdapter.PosterHolder, position: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
class PosterHolder (v: View) : RecyclerView.ViewHolder(v), View.OnClickListener {
override fun onClick(p0: View?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
。我对Kotlin来说相当新,所以我知道我会犯一个愚蠢的错误,但在这种情况下,我无法弄清楚我做错了什么。
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<cache
name="path.ENTITY"
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
<persistence strategy="localTempSwap"/>
/>
</ehcache>
答案 0 :(得分:1)
尝试此修复:
class RecyclerAdapter : RecyclerView.Adapter<RecyclerAdapter.PosterHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PosterHolder? {
return null
}
override fun onBindViewHolder(holder: PosterHolder, position: Int) {
}
override fun getItemCount(): Int {
return 0
}
inner class PosterHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}
要使用Android Studio将java文件转换为kotlin文件,请选择 Code-&gt;将java文件转换为kotlin文件。
答案 1 :(得分:0)
我真的不得不重新实现这些功能。我认为这是一个Android Studio问题,而不是Kotlin。这是我最新的代码:
class RecyclerAdapter: RecyclerView.Adapter<PosterHolder>(){
override fun onBindViewHolder(holder: PosterHolder, position: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PosterHolder{
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getItemCount(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
class PosterHolder (v: View) : RecyclerView.ViewHolder(v), View.OnClickListener {
override fun onClick(p0: View?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}