库折叠单元格android不工作,给出null不能转换为非null错误 图书馆
回购: 版本: 折叠单元:折叠单元:1.2.3 当我试图从github repo运行折叠单元格列表示例时,我遇到了一些问题,我收到了以下错误: E/AndroidRuntime:致命异常:主 流程:com.rebocar.guincho7,PID:13693 kotlin.TypeCastException:null不能强制转换为非null类型com.ramotion.foldingcell.foldingcell 在com.rebocar.guincho7.listview.FoldingCellListAdapter.getView(FoldingCellListAdapter.kt:26)上 错误指向getView代码:库折叠单元格android不工作,给出null不能转换为非null错误 图书馆,android,kotlin,Android,Kotlin,回购: 版本: 折叠单元:折叠单元:1.2.3 当我试图从github repo运行折叠单元格列表示例时,我遇到了一些问题,我收到了以下错误: E/AndroidRuntime:致命异常:主 流程:com.rebocar.guincho7,PID:13693 kotlin.TypeCastException:null不能强制转换为非null类型com.ramotion.foldingcell.foldingcell 在com.rebocar.guincho7.listview.FoldingC
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
如果我对以下行进行注释,则不会给出错误(但不会显示任何内容):
我的代码有什么问题,我只是添加了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>
你在遵循这个模式吗?也许你可以把你的实际布局粘贴到doublecheck上
<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>