override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
var myView=LayoutInflater.inflate(R.layout.row_custom_listitem, null)
var myNote=listNotes[p0]
myView.tvTitle.text=myNote.noteName
myView.tvDes.text=myNote.noteDes
The output is:
Unresolved reference: inflate
I selected import under the red mark at inflate, but there is no change. The packages have been imported but inflate is still underlined in red. Kindly help me to solve this issue.
override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
var myView= getLayoutInflater().inflate(R.layout.row_custom_listitem, null)
var myNote=listNotes[p0]
myView.tvTitle.text=myNote.noteName
myView.tvDes.text=myNote.noteDes
}
I modified my code as above, but I am not sure if this is right or will do the same job.
CodePudding user response:
Try this .
You have not return the view and must initialize the TextView
@Override
fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
val myView: View = layoutInflater.inflate(R.layout.row_custom_listitem, null)
val tvTitle= myView.findViewById<View>(R.id.tvTitle) as TextView
val tvDes= myView.findViewById<View>(R.id.tvDes) as TextView
tvTitle.text = "some value"
tvDes.text = "another value"
return myView
}
CodePudding user response:
It's a adapter class Override method...
val view = LayoutInflater.from(parent?.context).inflate(R.layout.row_custom_listitem,null)