I have an Android App based on Xamarin and MvvmCross. In that application there is a view with an ExpandableListView that I created on my own. Now this list displays several ite
It's a bit hard to follow the code snippet provided, but I would guess that the problem you are seeing is due to the fact that you are recycling the cell
and that each time you recycle it you are:
One way to solve this might be to use the WithClearBindingKey
fluent method to allow you to clear these bindings.
For example, if a binding is created as:
var set = this.CreateBindingSet<Cell, CellViewModel>();
set.Bind(text).To(vm => vm.TextValue).WithClearBindingKey("MyDynamicBindings");
set.Apply();
then just the bindings created with this tag can be cleared using:
this.ClearBindings("MyDynamicBindings");
Thanks stuart, but onestly I only pasted some of the code I wrote as my listadapter has become quite complex yet. So actually I already was recycling the controls that I created in code. However it seems I found the solution. I watched my app crashes lately and they all seemed to be because some binding calls the setter of an android widget (EditText, Spinner, Checkbox, etc.) which resulted in a native error. So I placed trace messages into the "Dispose" and "JavaFinalize" methods and as it turns out, the error always happened after some "JavaFinalize" calls. So what I did was to add the following code to all the controls, that I implemented as a "Bindable"something. (like the BindableEditText in the snippet above)
protected override void JavaFinalize()
{
if (this.BindingContext != null)
this.BindingContext.ClearAllBindings();
base.JavaFinalize();
}
So that totally does the job!
WARNING: I also had to add this to the "MvxListItemView". So maybe it should be added to the mvvmcross sources as well?