Tag: android arrayadapter

Kotlin的构造函数ArrayAdapter无法识别

我在Kotlin中扩展ArrayAdapter有一个问题。 这里代码: class SpinnerArrayAdapter(context: Context?, resource: Int, list: ArrayList<Pair>) : ArrayAdapter<Pair>(context, resource, list) { override fun getCount(): Int { return list.size //error list is unresolved } } 编辑与ArrayAdapter扩展无关。 我的问题是构造器的理解。

ArrayAdapter使用Kotlin android

对不起我的英语不好。 我学习kotlin,现在我需要写ArrayAdapter,但我有一些错误,当尝试做这个convertView = vi.inflate(resource, null) kotlin说我Val cannot be reassigned 。 在网站kotline我转换java类到kotlin类,并尝试做像这个网站。 为什么我有错,我该如何解决这个问题? open class MyAdapter(context: Context, resource: Int, list: ArrayList<MyItems>) : ArrayAdapter<MyItems>(context, resource, list) { var resource: Int var list: ArrayList<MyItems> var vi: LayoutInflater init { this.resource = resource this.list = list this.vi = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater } override fun getView(position: Int, convertView: View?, parent: […]

ArrayAdapter.clear kotlin

我正在努力学习kotlin,我想将我的一个Android项目从java转换为kotlin。 但是我有一个问题 override fun onResponse(call: Call<List<CitySearch>>?, response: Response<List<CitySearch>>?) { if(response != null && response.isSuccessful) { val list = response.body() cityAdapter.clear() if(list != null && !list.isEmpty()){ cityAdapter.addAll(list) listView.visibility = View.VISIBLE recyclerView.visibility = View.GONE cityName.visibility = View.GONE } } } 我得到的错误操作不支持只读集合在与cityAdapter.clear()行kotlin.collections.EmptyList.clear()我不知道如何解决它。 对于所有的项目,请检查 WeatherFragment有问题的历史版本 当前版本