Reputation: 137
First of all I want to say that I'm developing this in Xamarin Mono for Android with C# and not java.
My problem is that I can't get any event to trigger when the user has selected a item for the AutoCompleteTextView.
Anyone who sees what is wrong here?
I've got the following xaml code
<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" />
And then I've got the following code in a fragment
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;
}
Upvotes: 1
Views: 2081
Reputation: 1292
You should subscribe on ItemClick
event in your ListView
_yourAutoCompleteTextView.ItemClick += _yourAutoCompleteTextView_ItemClick;
private void _yourAutoCompleteTextView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
string selection = ArticleNumberTbox.Text;
}
Upvotes: 4