SortableTableView icon indicating copy to clipboard operation
SortableTableView copied to clipboard

Header Click Listener not working

Open guru2610 opened this issue 7 years ago • 6 comments

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

guru2610 avatar Nov 05 '18 19:11 guru2610

Yeah I can't get this to work either -

The addDataClickListener is working as expected, but the addHeaderClickListener is 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,

Nefariis avatar Jan 29 '19 21:01 Nefariis

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, Ingo

ISchwarz23 avatar Jan 30 '19 07:01 ISchwarz23

so

      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.SortableTableView

Nefariis avatar Jan 30 '19 17:01 Nefariis

Please also change TableView to SortableTableView in your layout file.

ISchwarz23 avatar Jan 30 '19 18:01 ISchwarz23

Awesome! Thank you so much for the quick responses.

Do you have a "buy a beer" link?

Nefariis avatar Jan 30 '19 18:01 Nefariis

Yes, in case you have PayPal: https://www.paypal.me/ISchwarz23

ISchwarz23 avatar Jan 30 '19 19:01 ISchwarz23