【问题标题】:MvxAutoCompleTextView loses binding on PatialTextMvxAutoCompleTextView 失去对 PatialText 的绑定
【发布时间】:2015-01-09 22:18:57
【问题描述】:

我正在使用 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 时,您可能会注意到“等待 ac 开始”。

我还注意到,一旦它第一次过滤并且您添加其他文本以进一步过滤列表,绑定到 PartialText 的属性的设置器就永远不会被调用。当你退格时也会发生同样的事情。

<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(); } }

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

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

干杯!

詹姆

【问题讨论】:

    标签: c# android mono mvvmcross


    【解决方案1】:

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

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

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

    WRT 你的搜索有时是一个字符我建议将 Debug.WriteLine 添加到 SearchTerm 和 Debug.WriteLine 的设置器中,围绕过滤器中的搜索调用。您将在错误的时间更新和响应 SearchTerm 更改的某个地方。

    附言您可能已经这样做了,但以防万一,不要使用 VS 输出窗口来查看调试输出。使用 Android Device Log 窗口并按“stdout”过滤

    拍拍

    【讨论】:

    • 非常感谢帕特!正是您的相关回答为我指明了正确的方向。文本更改后,我必须在适配器上调用 NotifyDataSetChanged。
    • 很高兴你把它修好了。更新 ItemsSource 时应该调用 NotifyDataSetChanged
    【解决方案2】:

    可能是因为链接器没有设置绑定吗?在这种情况下,您可以像这样将它添加到您的 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;
            }
    

    【讨论】:

      猜你喜欢
      • 2019-02-17
      • 1970-01-01
      • 1970-01-01
      • 2013-10-23
      • 1970-01-01
      • 2021-07-08
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      相关资源
      最近更新 更多