Repository navigation
Header Click Listener not working #166
Description
Activity
Yeah I can't get this to work either -
The
addDataClickListeneris working as expected, but theaddHeaderClickListeneris not.Here is my code [Kotlin]
class MainActivity : AppCompatActivity(), TableHeaderClickListener, TableDataClickListener<Array<String>> { private lateinit var tableView: TableView<Array<String>> private lateinit var mContext: Context override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mContext = this setContentView(R.layout.activity_main) tableView = this.findViewById<View>(R.id.tableView) as TableView<Array<String>> tableView.headerAdapter = SimpleTableHeaderAdapter(mContext, R.string.header_col1, R.string.header_col2, R.string.header_col3, R.string.header_col4, R.string.header_col5, R.string.header_col6) tableView.dataAdapter = SimpleTableDataAdapter(mContext, sortColumn(3, mContext)) tableView.addDataClickListener(this) tableView.addHeaderClickListener(this) } override fun onDataClicked(rowIndex: Int, clickedData: Array<String>?) { // This is working as expected Log.i("testapp", clickedData?.contentToString()) } override fun onHeaderClicked(columnIndex: Int) { // This is not working at all Log.i("testapp", columnIndex.toString()) } }Am I missing something?
Thanks,
Hi @Nefariis,
No, you do not miss anything. This is an issue in the TableView that needs to be fixed.
Meanwhile you can just replace the TableView by an SortableTableView as a workaround.Best regards,
Ingoso
private lateinit var tableView: TableView<Array<String>> tableView = this.findViewById<View>(R.id.tableView) as TableView <Array<String>>to
private lateinit var tableView: SortableTableView<Array<String>> tableView = this.findViewById<View>(R.id.tableView) as SortableTableView <Array<String>>Now the app crashes when it loads with this message -
Caused by: java.lang.ClassCastException: de.codecrafters.tableview.TableView cannot be cast to de.codecrafters.tableview.SortableTableViewPlease also change TableView to SortableTableView in your layout file.
Awesome! Thank you so much for the quick responses.
Do you have a "buy a beer" link?
Yes, in case you have PayPal: https://www.paypal.me/ISchwarz23
https://github.com/ISchwarz23/SortableTableView#header-click-listening
I have followed this doc, But no luck in header click listener.
TableData click listener working fine