Closed pandalion98 closed 4 years ago
Upon further investigation, it seems that the crash is caused when hiding a column, and the column beside it has a different ViewType
. This then causes onBindCellViewHolder
to fail, depending on how the ViewHolder
is implemented.
I think the main problem is that the column indexes/positions temporarily change when showing and hiding columns.
I did not expect that; what I expected was that the column simply disappeared from view without changing the table data.
Any proposed fixes?
Related issues: #163 #172
Resolved: I implemented the ViewType
logic within the ViewHolder
itself.
My adapter now always returns 0 for the cell ViewType
override fun getCellItemViewType(position: Int): Int {
return 0
}
And I don't use multiple Cell ViewHolders anymore. My CellModel has a type
argument
class CellModel(private val mId: String, val data: Any, var type: String) :
ISortableModel {
...
}
}
So that when my adapter binds it
override fun onBindCellViewHolder(h: AbstractViewHolder, m: CellModel?, col: Int, row: Int) {
m ?: return // Make sure CellModel is not null, else do not bind.
(h as CellViewHolder).setCellModel(m)
}
The ViewModel just declares the needed view as View.VISIBLE:
private fun setViews(model: CellModel) {
when (model.type) {
"text" -> {
textView.visibility = View.VISIBLE
textView.setText(model.data as String)
}
"checkbox" -> {
checkBox.visibility = View.VISIBLE
cb.isChecked = model.data as Boolean
}
}
}
Unfortunately, what this means is that all the views I need (e.g. CheckBox and TextView) needs to be contained in one XML file, with android:visibility="gone"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="@dimen/_23sdp"
android:gravity="center">
<CheckBox
android:id="@+id/cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:visibility="gone" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:textSize="@dimen/_8ssp"
android:visibility="gone" />
</LinearLayout>
I'm looking for the ability to show/hide multiple columns at the press of a button.
As an example, within the test app's RowHeaderLongPressPopup.java, I modified
onMenuItemClick
to readSo in theory, this should hide the first 5 columns. However, the entire app crashes instead.
Stack trace: