SeparatorColor of ListView is NOT updated dynamically.
AView bline; UpdateSeparatorVisibility(cell, cellIsBeingReused, isHeader, nextCellIsHeader, layout, out bline); UpdateSeparatorColor(isHeader, bline);
void OnItemTapped(object sender, ItemTappedEventArgs e) { if (e == null) return; // has been set to null, do not 'process' tapped event Debug.WriteLine("Tapped: " + e.Item); _showRedSeparator = !_showRedSeparator; listView.SeparatorColor = _showRedSeparator ? Color.Red : Color.Green; ((ListView)sender).SelectedItem = null; // de-select the row }
the separator color is not changed in android if tapp on list item
any update?
Hi Team / @hartez ,
I'd like to work on this and fix it. I've gone through its existing implementation (thanks to @bill2004158 for providing excellent-report of this issue) and noticed few things (seems more of bugs even with current version of Xamarin.Forms):
First of all, the current issue (mentioned by @bill2004158 ) is not limited to SeparatorColor but also impacts SeparatorVisibility (this also won't update dynamically).
This is due to the cellIsBeingReused code logic written before checking the current value of _listView.SeparatorVisibility or _listView.SeparatorColor.
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs#L668
We can actually improve the way we call UpdateSeparatorVisibility and UpdateSeparatorColor methods to draw the divider control by checking the current state of Separator before calling it, something like this:
AView bline;
bool isSeparatorVisible = _listView.SeparatorVisibility == SeparatorVisibility.Default;
if (isSeparatorVisible)
{
UpdateSeparatorVisibility(cell, cellIsBeingReused, isHeader, nextCellIsHeader, layout, out bline);
UpdateSeparatorColor(isHeader, bline);
}
UpdateSeparatorVisibility method, in the event where lets say cellIsBeingReused is true (i.e. ListView has been rendered), we should either fetch existing divider view (if possible to do) or create new (similar to existing LOC#674) and assign it to bline before return; statement. We should be also removing the below line from this method as it is already being verified as a boundary condition (in previous step):bool isSeparatorVisible = _listView.SeparatorVisibility == SeparatorVisibility.Default;Basically the improvements are around the way we call Update Separator methods. We should ideally be checking if there's something to update (considering its current value) before calling it and then reusing the cellIsBeingReused logic for performance improvement. Please provide your feedback on the above specifications and if I can proceed further to fix this.
Thanks!
@techduggu That all sounds reasonable to me. If you want to take a crack at it, we'd love to see the PR!
Already on it. Will be raising it soon!