- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试在 Kotlin 中创建自定义适配器类时出现上述错误
源代码
MainActivity.kt
var adapterC:CustomAdapter = CustomAdapter(this,Statearray)
spinnerState.adapter=adapterC
CustomAdapter.kt
class CustomAdapter(val activity: Activity,val array:JSONArray) : BaseAdapter(), ListAdapter
{
lateinit var ItemName: TextView
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
var view=convertView
if (view == null)
view = activity.layoutInflater.inflate(R.layout.spinnerlayout, null)
try {
ItemName = view?.findViewById(R.id.ItemName) as TextView
val obj = array.getJSONObject(position)
ItemName.setText(obj.getString("Name"))
view.setTag(obj.getString("Id"))
} catch ( e:JSONException) {
Log.e("At Custom Class",e.toString())
}
return view
}
override fun getItem(position: Int): JSONObject {
return array.optJSONObject(position)
}
override fun getItemId(position: Int): Long {
var jsonObject=getItem(position)
return jsonObject.optLong("id")
}
override fun getCount(): Int {
return array.length()
}
}
需要帮助我不知道我做错了什么。
最佳答案
我终于弄明白了..问题是,我使用的是仅支持 ArrayAdapter 的微调器库
我使用的库是
com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1
它只支持数组适配器
关于android - java.lang.ClassCastException : CustomAdapter cannot be cast to android. widget.ArrayAdapter 在 Kotlin ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50362896/
要更新 Listview 我们可以做以下两件事: 1) 创建一个新的ArrayAdapter,并在每次更新数据时将其绑定(bind)到ListView。 this.listView.setAdapte
基本上我所拥有的是一个显示 ListView 的 fragment 。它目前使用 ArrayAdapter。但是,我正在尝试扩展 ArrayAdapter 以制作我自己的自定义适配器。然后,当我更改代
这真的很奇怪。 当我为 ListView 使用标准 ArrayAdapter 时,调用 setItemChecked 工作正常 但是当使用定制的 ArrayAdapter 时它不会。 原因是什么?这是
我想在我的 android 应用程序中使用 AutoCompleteTextView。我知道如何将它与简单的字符串数组一起使用,但我希望 AutoCompleteTextView 使用对象列表来执行完
问题总结:adapter和spinner都在Spinner Activity中。一旦用户选择了一个名字,它就会将它们发送到主 Activity 。我想从另一个 Activity 中调用 ArrayAd
lang.NullPointerException android.widget.ArrayAdapter.init(ArrayAdapter.java)只是将 Arraylist 值添加到 cust
在开发 Android 应用程序时,我从类似于“Item 1”、“Item 2”、“Item 3”的网站上得到了一行响应我需要将这一行转换为一个列表,以便在 simplelistitem 的数组适配器
您好,我如何检查复选框是否已选中,以及是否已选中我怎样才能删除有问题的行?谢谢你 数组适配器: public class Todoadapter extends ArrayAdapter {
https://developer.android.com/guide/topics/ui/declaring-layout#FillingTheLayout 在这些文档中,我们有以下代码 fragm
我有一个填充数据“neededRepData”的列表,我正在尝试将此列表添加到我的适配器中,但遇到了问题。下面是我的 Reps 类和我的方法(来自另一个类)来迭代所需的 RepData。 public
拥有可以处理多种对象类型的数组适配器的最佳实践是什么? Adapter extends ArrayAdapter 我有 3 种类型的类(class) A.class , B.class , C.cla
我正在制作一个将 JSON 数据解析为 ListView 的应用程序。这对我不起作用;它没有给我任何数据。 这是我的代码: public class MainActivity extends AppC
我有一个 Activity 从另一个 Activity 加载sharedPreference,并从当我编译我的应用程序时,使用 arrayAdpter 将 sharePreferenece 放入 li
我尝试使用 arrayAdapter 自定义将图像和文本加载到 ListView,但加载图像失败 这是我的数组适配器 public class CustomAdapter extends ArrayA
我在使用我的应用程序时遇到问题。我刚刚开始开发该应用程序,到目前为止只花了大约 15 个小时。但我遇到了障碍。通常我可以用谷歌搜索障碍,我的大部分答案都来自这个论坛! 所以我希望我能找到解决方案。下面
我之前曾用其他适配器(如 SimpleAdapter)问过这个问题,但简单适配器的解决方案不适用于 ArrayAdapter。在 SimpleAdapter 中,我获得了屏幕宽度和高度,然后将其传递给
我有 3 个类(class),我希望使用自动完成文本框向用户显示来自 Web 服务(rest api)的某些数据(又名城市)。我已经在我自己的应用程序的各种功能上使用了这个实现,但是由于某种原因,te
我正在从 Google App Engine 获取字符串形式的数据,因此我必须在一个线程中执行此操作。接下来我想在 ListView 中显示它,我正在尝试执行类似以下代码的操作: public voi
我有一个带有自定义 ArrayAdapter 的 ListView ,它设置在一个 fragment 中。仅设置 ListView 中的第一行。 这可能是一般使用带有 fragment 的 ListV
我正在尝试修改 MyKong 中的代码,添加一些更改 TextView 字体的行,但是当我尝试运行时遇到强制关闭。 这里是 MobileArrayAdapter.java > package com.
我是一名优秀的程序员,十分优秀!