gpt4 book ai didi

c# - Xamarin Android 中的自动完成 TextView

转载 作者:行者123 更新时间:2023-11-29 20:19:53 24 4
gpt4 key购买 nike

我是 Xamarin 的新手。我正在尝试将对象绑定(bind)到 Xamarin Android 中的 AutocompleteTextView。我能够附加适配器,但是当我在 AutoCompleteTextView 中键入文本时,对象按原样显示,而不是文本。我为 Item Click 添加了事件处理程序,并且能够获取我想要显示的值。以下是我的代码以及有关如何将值显示为建议的任何帮助或指示。

主要 Activity

公共(public)类 MainActivity : Activity { 整数计数 = 1;

    protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);

// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);

//button.Text =
MainActivityModel Mv = new MainActivityModel();
ArrayAdapter<AutoCompleteTextModel> adapter = new ArrayAdapter<AutoCompleteTextModel>
(this,Android.Resource.Layout.SimpleDropDownItem1Line,Mv.StationsList);

AutoCompleteTextView actv = FindViewById<AutoCompleteTextView>(Resource.Id.source);

actv.Adapter = adapter;
//actv.Threshold = 1;

actv.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => {
actv.Text = Mv.StationsList[e.Position].StationName;
};

actv.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {

new ArrayAdapter (
this,
Android.Resource.Layout.SimpleListItem1,
Mv.StationsList.FindAll (a => a.StationName.Contains(actv.Text)).ToArray ());
};


button.Click += delegate {
button.Text = string.Format ("{0} clicks!", count++);
};
}
}

自动完成 TextView 模型

公共(public)类 AutoCompleteTextModel { 公共(public)字符串 StationName { get;放; } public int StationId { 得到;放;

    public AutoCompleteTextModel ()
{
}
}

公共(public)类 MainActivityModel { public List StationsList;

    public MainActivityModel ()
{
StationsList = new List<AutoCompleteTextModel> ();

StationsList.Add (new AutoCompleteTextModel () {StationId = 1, StationName = "Chennai Beach"
});
StationsList.Add (new AutoCompleteTextModel () {StationId = 1, StationName = "Chennai Fort"
});
StationsList.Add (new AutoCompleteTextModel () {StationId = 1, StationName = "Chennai Park"
});
StationsList.Add (new AutoCompleteTextModel () {StationId = 1, StationName = "Chennai Egmore"
});
StationsList.Add (new AutoCompleteTextModel () {StationId = 1, StationName = "Chetpet"
});
}

最佳答案

enter image description here

_objGeneralDetailProductType 是 AutoCompleteTextView 的对象类型

您可以尝试在自动完成中绑定(bind)列表,因为在我手中,我正在使用它并且工作正常。

关于c# - Xamarin Android 中的自动完成 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33356305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com