SortableTableView
SortableTableView copied to clipboard
Set selected row backgroundColor
I'm trying to find an easy way to set (change) the background color of selected a row when its clicked on and keep the background color after sorting rows. Do it as ListView <ListView .... android:choiceMode="singleChoice" android:listSelector="#4d90fe"/>
Hi @Pecto2000,
in deed this is a feature that has not been implemented. When the user clicks on an item, this item is selected. But when the table is filtered, the selection will stay at the index and will not move as the selected item. Another issue is, that the selection is lost on orientation change.
Thanks for the hint. This is a feature that will come in a future release, but unfortunatelly I am not able to tell you, when this will be. You are welcome to create a pull request containing this feature ;)
Best regards, Ingo
Thank you for your reply. I will try to deal with this topic.
- Is there a way to retrieve a specific row [getRowView(rowIndex, ...)] in the tableView (as getCellView)?
- Is there a way to retrieve the rows number [rowCount] in the tableView (as columnCount) ?
- Is there a way to retrieve list of Rows My immediate goal is to get a specific row (+ all rows ) in the tableView and do a foreach on this list.
Thank you for this very nice View ! i'm also very interrested by this feature :) also a get_RowSelected() would be nice to play with it.
Hi @Pecto2000,
Reply to 1)
The TableDataAdapter
is able to give you the complete row view by calling the getView()
method.
Reply to 2)
Again the TableDataAdapter
is able to give the number of rows by calling the getCount()
method.
Reply to 3)
Do you need to have all rows or all row data? You can get all the row data by calling TableDataAdapter#getData()
.
Hi! How to highlight a selected row please?
Hi, I'm currently looking for a solution for the selection, but I have some problems.
Hi, Still no solution for selector ?
No, it is not as easy to achive as expected.
Until the owner officially implements highlighting of the selected item, here is a workaround... assuming you already have your own way of storing the rowData on orientation change (similar to setRetainInstance(true) in fragments) then to change the background color of the row you call yourSortableTableView.getDataAdapter().getView(rowIndex, convertView, parentViewGroup).setBackgroundColor(yourColor) and after that you MUST call yourSortableTableView.getDataAdapter().notifyDataSetChanged().
a sample updateTable function
Edit: okay I found out that changing background on one even or odd row will change the background for all odd/even rows
Edit2: ok I managed to get highlighting working, but instead of setting background color to whole row, I had to set the background color of each cellView in the row
Hi @PewPewKenshin,
you can also implement a new TableDataRowBackgroundProvider
that checks, if the data item is selected and returns the desired color. I think think that this is more easy than set the background color for every single cell in a row.
Best regards, Ingo
Hi @Pecto2000 ,
unfortunately selection is not supported by this library. But there is a new generation of this library available at sortabletableview.com, which support the selection feature and much more new features. This new library is based on the recycler view, so it uses up to date technology which enables better performance.
Best regards, Ingo
Hi, I'm currently looking for a solution for the selection, but I have some problems.
try your best sir
Hi @PewPewKenshin,
you can also implement a new
TableDataRowBackgroundProvider
that checks, if the data item is selected and returns the desired color. I think think that this is more easy than set the background color for every single cell in a row.Best regards, Ingo
Is there a way to implement the custom TableDataRowBackgroundProvider without having to re-populate the table again? I tried calling my custom TableDataRowBackgroundProvider inside my addDataClickListener but I have to "refresh" the table in order for the changes to be visible.