更新时间:2023-09-16 08:03:58
您必须使用 API 级别 26(或更高).此版本更改了 View.findViewById()
的签名 - 请参阅此处 https://developer.android.com/about/versions/oreo/android-8.0-changes#fvbi-signature
You must be using API level 26 (or above). This version has changed the signature of View.findViewById()
- see here https://developer.android.com/about/versions/oreo/android-8.0-changes#fvbi-signature
因此,在您的情况下,findViewById
的结果不明确,您需要提供类型:
So in your case, where the result of findViewById
is ambiguous, you need to supply the type:
1/改变
val listView = findViewById(R.id.list) as ListView
to
val listView = findViewById
2/改变
this.label = row?.findViewById(R.id.label) as TextView
to
this.label = row?.findViewById
请注意,在 2/中只需要强制转换,因为 row
可以为空.如果 label
也可以为空,或者如果您使 row
不可为空,则不需要.
Note that in 2/ the cast is only required because row
is nullable. If label
was nullable too, or if you made row
not nullable, it wouldn't be required.