MvxAutoCompleTextView 失去对 PatialText 的绑定

MvxAutoCompleTextView loses binding on PatialText

我正在使用 MvxAutoCompleTextView 并且我已确认 ItemsSource 和 SelectedObject 已正确绑定并正常工作(我添加了一些代码,当小部件获得焦点时,它会执行 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.

时,您可能会注意到 'Wait starting for ac'

我还注意到,一旦它第一次过滤并且您添加额外的文本以进一步过滤列表,绑定到 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" />

这是绑定到 PartialText 的 属性:

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

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

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

干杯!

海梅

会不会是因为链接器的原因没有设置绑定?在这种情况下,您可以像这样将它添加到您的 LinkerPleaseInclude.cs 文件中:

public void Include(MvxAutoCompleteTextView text)
        {
            text.TextChanged += (sender, args) => text.Text = "" + text.Text;
            text.PartialTextChanged += (sender, args) => text.Text = "" + text.Text;
            text.SelectedObjectChanged += (sender, args) => text.Text = "" + text.Text;
        }

Android 的 AutoCompleteTextView 是真正的 PITA。您看到 "the setter of the property bound to PartialText never gets called." 的可能原因是控件仍在等待 ItemsSource 从之前的更改中更新。

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

当您看到 "mvx:Diagnostic: Wait starting for YOURPARTIALTEXT" 但没有匹配的 "mvx:Diagnostic:116.82 Wait finished..."

时,您将知道它已停止工作

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

p.s。你可能已经这样做了,但以防万一,不要使用 VS 输出 Window 来观察调试输出。使用 Android 设备日志 window 并按 "stdout"

过滤

帕特