android - 库折叠单元格 android 不工作,给 null 不能转换为非 null 错误
问题描述
图书馆
回购:
https://github.com/Ramotion/folding-cell-android/
版本:
com.ramotion.foldingcell:折叠单元:1.2.3
当我尝试从 github repo运行折叠单元列表示例时,我遇到了一些问题,我收到了这个错误:
E/AndroidRuntime:致命异常:主进程:com.rebocar.guincho7,PID:13693 kotlin.TypeCastException:null 不能在 com.rebocar.guincho7.listview.FoldingCellListAdapter 转换为非空类型 com.ramotion.foldingcell.FoldingCell。 getView(FoldingCellListAdapter.kt:26)
错误指向getView代码:
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { // get item for selected view
val item = getItem(position)
// if cell is exists - reuse it, if not - create the new one from resource
val cell = convertView as FoldingCell
val viewHolder: ViewHolder
// for existing cell set valid valid state(without animation)
if (unfoldedIndexes.contains(position)) {
cell.unfold(true)
} else {
cell.fold(true)
}
viewHolder = cell.tag as ViewHolder
if (null == item) return cell
// bind data from selected element to view through view holder
// bind data from selected element to view through view holder
viewHolder.price!!.text = item.price
viewHolder.time!!.text = item.time
viewHolder.date!!.text = item.date
viewHolder.fromAddress!!.text = item.fromAddress
viewHolder.toAddress!!.text = item.toAddress
viewHolder.requestsCount!!.text = item.requestsCount.toString()
viewHolder.pledgePrice!!.text = item.pledgePrice
// set custom btn handler for list item from that item
// set custom btn handler for list item from that item
if (item.getRequestBtnClickListener() != null) {
viewHolder.contentRequestBtn!!.setOnClickListener(item.getRequestBtnClickListener())
} else { // (optionally) add "default" handler if no handler found in item
viewHolder.contentRequestBtn!!.setOnClickListener(defaultRequestBtnClickListener)
}
return cell
}
第 26 行是: val cell = convertView as FoldingCell
如果我评论以下几行,它不会给出错误(但不显示任何内容):
mainListView.adapter = adapter
mainListView.setOnItemClickListener { _, view, pos, _ ->
// toggle clicked cell state
(view as FoldingCell).toggle(false)
// register in adapter that state for selected cell is toggled
adapter.registerToggle(pos)
}
我的代码有什么问题,我真的只是从 repo 中添加了示例,任何人都知道可能是什么?
解决方案
在基本用法部分,它说您的布局中必须具有此特定结构
<com.ramotion.foldingcell.FoldingCell
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/folding_cell"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/cell_content_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_green_dark"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="250dp" />
</FrameLayout>
<FrameLayout
android:id="@+id/cell_title_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/holo_blue_dark" />
</FrameLayout>
</com.ramotion.foldingcell.FoldingCell>
你遵循这个模式吗?也许你可以粘贴你的实际布局来仔细检查?
推荐阅读
- push - ejabberd mod_push 和 mod_push_keepalive 不启动
- sql - 如何使用 sql server 根据上一行和下一行显示记录
- reactjs - React componentDid mount 获取异步图像。如果在更改页面之前没有完成,如何取消请求?
- codenameone - CN1:带 Alpha 通道的渐变
- assembly - 在运行时中断汇编指令
- bash - 如何在 YAML 文件中对 bash 脚本进行 lint
- javascript - 比较两个具有 css-properties 的数组
- asp.net - Azure AD 回复 url 在 html 处理程序上失败
- matlab - 使用Matlab检测移动车辆的车辆信号灯
- vba - 拆分长度和字符不同的字符串