Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 523 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Not enough information to infer parameter T" with Kotlin and Android

#1
I'm trying to replicate the following ListView in my Android app using Kotlin:

[To see links please register here]

.

Unfortunately I'm getting an error I'm unable to resolve myself.
Here's my code:

MainActivity.kt:

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val listView = findViewById(R.id.list) as ListView
listView.adapter = ListExampleAdapter(this)
}

private class ListExampleAdapter(context: Context) : BaseAdapter() {
internal var sList = arrayOf("Eins", "Zwei", "Drei")
private val mInflator: LayoutInflater

init {
this.mInflator = LayoutInflater.from(context)
}

override fun getCount(): Int {
return sList.size
}

override fun getItem(position: Int): Any {
return sList[position]
}

override fun getItemId(position: Int): Long {
return position.toLong()
}

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? {
val view: View?
val vh: ListRowHolder

if(convertView == null) {
view = this.mInflator.inflate(R.layout.list_row, parent, false)
vh = ListRowHolder(view)
view.tag = vh
} else {
view = convertView
vh = view.tag as ListRowHolder
}

vh.label.text = sList[position]
return view
}
}

private class ListRowHolder(row: View?) {
public val label: TextView

init {
this.label = row?.findViewById(R.id.label) as TextView
}
}
}

The layouts are exactly as here:

[To see links please register here]


The full error message I'm getting is this:
**Error:(92, 31) Type inference failed: Not enough information to infer parameter T in fun <T : View!> findViewById(p0: Int): T!
Please specify it explicitly.**

I'd appreciate any help I can get.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through