如何在按钮单击时获取autocompleteTextView的值?

时间:2018-04-16 19:03:20

标签: c# android forms xamarin buttonclick

我想要一些帮助。我有这段代码:

{{1}}

所以我想将autocompleteTextView的文本添加到我的listview适配器,但我不能在那里做,因为那里不存在。所以我创建了一个我makde等于mautoCompleteTextView.Text的字符串,但它将为空,因为它将在程序启动时运行,此时用户尚未执行任何操作。所以我的问题是当用户按下按钮时我无法获得mautoCompleteTextView.Text。如果有人能够停下来那将是非常感谢。

1 个答案:

答案 0 :(得分:0)

您在方法中声明mautoCompleteTextView,因此只能在该方法中本地使用。

如果您将声明移到方法之外,那么mautoCompleteTextView将在整个课程中可用。

// declare it here
AutoCompleteTextView mautoCompleteTextView;

// then instantiate it within the method
public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
    {
       ... // code omitted

       mautoCompleteTextView = view.FindViewById<AutoCompleteTextView>(Resource.Id.autoCompleteTextView1);

       ... // code omitted
    }