Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header Click Listener not working #166

Open
guru2610 opened this issue Nov 5, 2018 · 6 comments
Open

Header Click Listener not working #166

guru2610 opened this issue Nov 5, 2018 · 6 comments

Comments

@guru2610
Copy link

guru2610 commented Nov 5, 2018

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
Copy link

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
Copy link
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

@Nefariis
Copy link

Nefariis commented Jan 30, 2019

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
Copy link
Owner

Please also change TableView to SortableTableView in your layout file.

@Nefariis
Copy link

Awesome! Thank you so much for the quick responses.

Do you have a "buy a beer" link?

@ISchwarz23
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants