首先,我想说的是我在Xamarin Mono for Android中用C#而不是java开发它。
我的问题是,当用户为AutoCompleteTextView选择了一个项目时,我无法触发任何事件。
任何人在这里看到了什么问题?
我已获得以下xaml代码
<AutoCompleteTextView
android:id="@+id/ArticleNrTbox"
android:layout_width="160dp"
android:layout_height="40dp"
android:background="@drawable/EditTextLarge"
android:textColor="#838282"
android:paddingLeft="8dp"
android:inputType="number" />
然后我在片段
中获得了以下代码View ThisView = null;
AutoCompleteTextView ArticleNumberTbox;
List<ArticleStruct> articles;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
ThisView = inflater.Inflate(Resource.Layout.MaterialReport, container, false);
ArticleNumberTbox = ThisView.FindViewById<AutoCompleteTextView>(Resource.Id.ArticleNrTbox);
articles = ArticlesDatabase.GetArticles().ToList();
var aList = new List<string>();
foreach (var article in articles)
aList.Add(article.ArticleNumber + "(" + article.Term + ")");
var adapter = new ArrayAdapter<string>(ThisView.Context, Resource.Layout.SimpelListItem, aList);
ArticleNumberTbox.Adapter = adapter;
ArticleNumberTbox.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(ArticleNumberTbox_ItemSelected);
}
void ArticleNumberTbox_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
string selection = ArticleNumberTbox.Text;
}
答案 0 :(得分:2)
您应该在ItemClick
ListView
个活动
_yourAutoCompleteTextView.ItemClick += _yourAutoCompleteTextView_ItemClick;
private void _yourAutoCompleteTextView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
string selection = ArticleNumberTbox.Text;
}