问题描述
我在 Xamarin Android AutoCompleteTextView 周围使用 MVMCross 的包装器.
I am using MVVMCross's wrapper around the Xamarin Android AutoCompleteTextView.
我使用 PartialTextChanged 更改事件来表示我需要从视图调用 ViewModel 以获得更多建议.
I use the PartialTextChanged changed event to signal that I need to call the ViewModel, from the View, to get some more suggestions.
这在用户从列表中选择一个项目之前都可以正常工作.在那之后,对文本的任何更改都不会导致 PartialTextChanged 事件触发.就好像一旦做出选择就关闭了过滤.
This works fine up to the point the user selects an item from the list. After that point no changes to the text will cause the PartialTextChanged event to fire. It is as if filtering is turned off once a selection has been made.
AutoCompleteTextView 上有一个 SetText 方法似乎可以打开/关闭过滤,但我不确定使用它的最佳方法.
There is a SetText method on the AutoCompleteTextView that seems to turn filtering onoff but I am unsure of the best way to use that.
TextChangedEvent 仍然像 AfterTextChanged 一样在控件上触发,只是不是 PartialTextChanged,它是驱动更新的那个.
The TextChangedEvent still fires on the control as does AfterTextChanged just not PartialTextChanged and it is that which drives the updates.
我已经通过 MVVMCross 源进行了调试,但看不到解决方案.大家有什么想法吗?
I have debugged through the MVVMCross source and cannot see a solution. Any have any ideas?
在哪里可以浏览它们的 mondroidxamarin android 代码?
Where can I browse them mondroidxamarin android code?
谢谢
推荐答案
在附上 MVVMCross 源代码并调试所有事件后,我发现在某些情况下我没有在 PartialText 属性被更改后更新 ItemsSource
After attaching the MVVMCross Source Code and debugging all the events I found that under certain circumstances I was not updating the ItemsSource after the PartialText property was being changed
FilteringAdapter 使用 ManualResetEvent 围绕对 PartialText 的更改,并且仅由 NotifyDataSetChanged 方法发出信号/设置.
The FilteringAdapter uses a ManualResetEvent around the change to PartialText and that is only signalledset by the NotifyDataSetChanged method.
发现这个之后,我还发现@slodge 在这个答案中也提到了这一点,无需在 ViewModel 上使用 Java.Lang.Object 即可自动完成 MVVM 和 Java Casting.一个直到现在我都过去的约束.
After finding this I also found that @slodge also mentions this in this answer, AutoComplete MVVM and Java Castings without using Java.Lang.Object on ViewModel. A constraint that until now had passed me by.
请注意,由于 Android 线程模型,必须PartialText 中的每一个变化都由最终的信号变化来满足ItemsSource - 这应该是对象集合中的单个更改而不是很多小的变化.
谢谢
这篇关于PartialTextChanged 在项目选择后停止在 MvxAutoCompleteTextView 上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!