I've extended ArrayAdapter for spinner:
class OrderAdapter(context: Context, resource: Int, objects: List<Order>) : ArrayAdapter<Order>(context, resource, objects) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? {
val view = super.getView(position, convertView, parent)
view?.let { view.find<TextView>(android.R.id.text1).text = getItem(position).name }
return view
}
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View? {
val view = super.getDropDownView(position, convertView, parent)
view?.let {view.find<TextView>(android.R.id.text1).text = getItem(position).name }
return view
}
}
I'm getting exception:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView
at com.github.blabla.endlesss.ui.adapter.OrderAdapter.getView(OrderAdapter.kt:0)
Any ideas how to fix it?
This issue was caused by incremental compile. Just needed to rebuild project after converting from Java.
Please check the sample below:
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View? {
return getCustomView(position, convertView, parent)
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? {
return getCustomView(position, convertView, parent)
}
fun getCustomView(position: Int, convertView: View?, parent: ViewGroup): View? {
val rootView: View? = LayoutInflater.from(context).inflate(R.layout.my_custom_view, parent, false)
return rootView
}
The returned value should be nullable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With