Skip to content

Header Click Listener not working #166

Description

@guru2610

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

Activity

  1. Nefariis commented on Jan 29, 2019

    @Nefariis

    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,

  2. ISchwarz23 commented on Jan 30, 2019

    @ISchwarz23
    Owner

    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

  3. Nefariis commented on Jan 30, 2019

    @Nefariis

    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

  4. ISchwarz23 commented on Jan 30, 2019

    @ISchwarz23
    Owner

    Please also change TableView to SortableTableView in your layout file.

  5. Nefariis commented on Jan 30, 2019

    @Nefariis

    Awesome! Thank you so much for the quick responses.

    Do you have a "buy a beer" link?

  6. ISchwarz23 commented on Jan 30, 2019

    @ISchwarz23
    Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions