我尝试使用MvxAutoCompleteTextView,但它在Debug中遇到以下输出:
mvx:诊断:3,57等待
开始
只要我在模拟器中启动我的应用程序(Android 4.3,硬件键盘禁用),我就会看到Wait starting for
消息,当我输入时,不会显示任何建议。
我的ViewModel:
public class FirstViewModel : MvxViewModel
{
public FirstViewModel()
{
ClearResults();
}
public string[] AutoCompleteSuggestions { get; set; }
private string _currentTextHint;
public string CurrentTextHint
{
get { return _currentTextHint; }
set
{
_currentTextHint = value;
base.RaisePropertyChanged(() => CurrentTextHint);
if (CurrentTextHint == null || CurrentTextHint.Length < 3)
ClearResults();
else
BeginSearchAsync();
}
}
private void ClearResults()
{
AutoCompleteSuggestions = new string[0];
base.RaisePropertyChanged(() => AutoCompleteSuggestions);
}
private async void BeginSearchAsync()
{
await Task.Delay(2000);
AutoCompleteSuggestions = new string[] { "test", "ok" };
base.RaisePropertyChanged(() => AutoCompleteSuggestions);
}
public string Selected { get; set; }
public string CurrentText { get; set; }
}
FirstView.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<MvxAutoCompleteTextView
android:id="@+id/autoCustomerName"
android:inputType="textPersonName"
android:layout_width="366.7dp"
android:layout_height="49.1dp"
android:paddingLeft="5dp"
android:completionThreshold="3"
android:hint="hint..."
android:gravity="left|center_vertical"
local:MvxBind="ItemsSource AutoCompleteSuggestions; PartialText CurrentTextHint; SelectedObject Selected; Text CurrentText;" />
</LinearLayout>
答案 0 :(得分:1)
首先,确保您的AutoCompleteSuggestions的setter触发它的PropertyChanged事件。当您使用属性的默认模板时,我不确定是否会发生这种情况。
其次,您需要在CurrentTextHint属性中执行额外的步骤。这是一个有效的链接。