kotlinandroid-studiooverridinggetview

'getView' overrides nothing


I am new about android studio. I tried to use ArrayAdapter. But when i complete my codes, it says "'getView' overrides nothing".I getting this error in "return teksatirview code. this is my arrayadapter class:

package com.example.burcrehberi
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import kotlinx.android.synthetic.main.teksatir.view.*


class BurcArrayAdapter(
var gelencontext: Context,
resource: Int,
textViewResourceId: Int,
var burcAdlari: Array<String>,
var burcTarih: Array<String>,
var burcResimleri: Array<Int>
) : ArrayAdapter<String>(gelencontext, resource, textViewResourceId, burcAdlari) {

override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {

    var teksatirview = convertView

    if (teksatirview == null) {

        var inflater = LayoutInflater.from(gelencontext)
        teksatirview = inflater.inflate(R.layout.teksatir, parent, false)


    }

    var burcImageView = teksatirview?.imgburcsembol
    var burcisim = teksatirview?.tvburcadi
    var burctarih = teksatirview?.tvburctarih

    burcImageView?.setImageResource(burcResimleri[position])
    burcisim?.setText(burcAdlari[position])
    burctarih?.setText(burcTarih[position])

    return teksatirview
}

}

Solution

  • Your problem in parent: ViewGroup?. According to signature it must be non-null type. But it's nullable in your signature, so it's completely different function in kotlin. Just change to:

     override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
    

    And return type View? to View too.