c# - MvxAutoCompleTextView 失去对 PatialText 的绑定(bind)

标签 c# android mono mvvmcross

我使用的是 MvxAutoCompleTextView,并且我已经确认 ItemsSource 和 SelectedObject 已正确绑定(bind)并正常工作(我添加了一些代码,当小部件获得焦点时,它会执行 ShowDropDown 并确保预期的项目在那里)。

当我开始键入以过滤列表时,问题就开始了。第一步,ItemsSource 被正确过滤。但我注意到有时它仅根据某些键入的字符进行过滤。有时是第一个字符,有时是前两个字符。基本上是命中注定的事情。下面是一个示例堆栈跟踪...

01-09 13:33:37.145 D/AbsListView( 3098): onDetachedFromWindow [0:] 01-09 13:33:37.185 D/AbsListView( 3098): Get MotionRecognitionManager mvx:Diagnostic:116.54 Wait starting for ac 01-09 13:33:37.395 I/mono-stdout( 3098): mvx:Diagnostic:116.54 Wait starting for ac [0:] mvx:Diagnostic:116.54 Wait starting for ac [0:] mvx:Diagnostic:116.82 Wait finished with 772 items for ac [0:] mvx:Diagnostic:116.82 Wait finished with 772 items for ac 01-09 13:33:37.745 I/mono-stdout( 3098): mvx:Diagnostic:116.82 Wait finished with 772 items for ac [0:] mvx:Diagnostic:117.03 Wait starting for ac [0:] mvx:Diagnostic:117.03 Wait starting for ac 01-09 13:33:37.805 I/mono-stdout( 3098): mvx:Diagnostic:117.03 Wait starting for ac 01-09 13:33:38.025 D/AbsListView( 3098): onDetachedFromWindow 01-09 13:33:38.095 D/AbsListView( 3098): Get MotionRecognitionManager

当我输入 acc 时,您可能会注意到“等待 ac 开始”。

我还注意到,一旦它第一次过滤并且您添加了额外的文本以进一步过滤列表,绑定(bind)到 PartialText 的属性的 setter 就永远不会被调用。退格时也会发生同样的事情。

<MvxAutoCompleteTextView android:id="@+id/autoComplete" android:layout_width="0dp" android:layout_weight="2" android:layout_marginLeft="5dp" android:layout_gravity="center_vertical|left" android:completionThreshold="1" local:MvxItemTemplate="@layout/template_autocomplete" local:MvxBind="ItemsSource Hazards; PartialText SearchTerm; SelectedObject SelectedHazard" style="@style/edit_text.medium.fill" />

这是绑定(bind)到 PartialText 的属性:

private string _searchTerm; public string SearchTerm { get { return _searchTerm; } set { _searchTerm = value; RaisePropertyChanged(() => SearchTerm); Filter(); } }

我做错了什么?我错过了什么吗?

我希望我解释清楚了。提前致谢。

干杯!

杰米

最佳答案

Android 的 AutoCompleteTextView 是一个真正的 PITA。您看到“绑定(bind)到 PartialText 的属性的 setter 永远不会被调用”的可能原因。是因为控件仍在等待 ItemsSource 从之前的更改中更新。

我有同样的问题并在这里回答,PartialTextChanged stops firing on MvxAutoCompleteTextView after Item selection .基本上,对 PartialText 的每次更改都必须导致对 ItemsSource 的更改。

当您看到“mvx:Diagnostic: Wait starting for YOURPARTIALTextX”但没有匹配的“mvx:Diagnostic:116.82 Wait finished...”时,您将知道它已停止工作

WRT 您的搜索有时会超出一个字符,我建议将 Debug.WriteLine 添加到 SearchTerm 的 setter 中,并在 Filter 中的搜索调用周围添加 Debug.WriteLine。在某个地方,您将在错误的时间更新和响应 SearchTerm 更改。

附注你可能已经这样做了,但以防万一,不要使用 VS 输出窗口来观察调试输出。使用 Android 设备日志窗口并按“stdout”过滤

帕特

关于c# - MvxAutoCompleTextView 失去对 PatialText 的绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27870172/

相关文章:

c# - C# 表达式使用什么类型的算法?

android - 如何在android中显示泰卢固语字体

c# - .NET 图形数据库

c# - "The path .. would result in a file outside the App Bundle and cannot be used"错误,单触摸/Xamarin

c# - 如何创建对象的内部搜索引擎

c# - EF6 FluentAPI,0 :1 Unidirectional

android - Kivy:跨平台通知图标

c# - 从 C# 访问 C 全局变量 'errno'

c# - 根据属性比较两个 List<Control> 之前/之后

Android:通过消息、G+、twitter、facebook 可靠地分享来自 Assets 的图像?