ISchwarz23 / SortableTableView

An Android library containing a simple TableView and an advanced SortableTableView providing a lot of customisation possibilities to fit all needs.
Apache License 2.0
1.05k stars 239 forks source link

Header Click Listener not working #166

Open guru2610 opened 5 years ago

guru2610 commented 5 years ago

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

Nefariis commented 5 years ago

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,

ISchwarz23 commented 5 years ago

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

Nefariis commented 5 years ago

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

ISchwarz23 commented 5 years ago

Please also change TableView to SortableTableView in your layout file.

Nefariis commented 5 years ago

Awesome! Thank you so much for the quick responses.

Do you have a "buy a beer" link?

ISchwarz23 commented 5 years ago

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