SortableTableView icon indicating copy to clipboard operation
SortableTableView copied to clipboard

Set selected row backgroundColor

Open Pecto2000 opened this issue 8 years ago • 13 comments

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"/>

Pecto2000 avatar Jun 08 '16 18:06 Pecto2000

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

ISchwarz23 avatar Jun 10 '16 18:06 ISchwarz23

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.

Pecto2000 avatar Jun 12 '16 12:06 Pecto2000

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.

giova-fr avatar Jun 15 '16 14:06 giova-fr

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().

ISchwarz23 avatar Jul 20 '16 16:07 ISchwarz23

Hi! How to highlight a selected row please?

Reagang avatar Aug 31 '16 21:08 Reagang

Hi, I'm currently looking for a solution for the selection, but I have some problems.

ISchwarz23 avatar Sep 02 '16 04:09 ISchwarz23

Hi, Still no solution for selector ?

ulaserdegor avatar Nov 18 '16 06:11 ulaserdegor

No, it is not as easy to achive as expected.

ISchwarz23 avatar Nov 18 '16 13:11 ISchwarz23

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

PewPewKenshin avatar Dec 05 '16 09:12 PewPewKenshin

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

ISchwarz23 avatar May 07 '17 10:05 ISchwarz23

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

ISchwarz23 avatar Nov 11 '17 15:11 ISchwarz23

Hi, I'm currently looking for a solution for the selection, but I have some problems.

try your best sir

omkarghurye1998 avatar Apr 20 '20 14:04 omkarghurye1998

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.

Fdde11 avatar May 15 '20 17:05 Fdde11