为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
DIEA 2021-04-06 13:14:29
我需要一些帮助。我有以下代码:string hozzaadnivalo;public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)        {            View view = LayoutInflater.From(container.Context).Inflate(Resource.Layout.pager_item, container, false);            container.AddView(view);            Button hozzaadas = view.FindViewById<Button>(Resource.Id.hozzaad);            var autoCompleteOptions = new string[] { "Sajt", "Tej", "Kecske", "Barátnő", "piros", "alma" };            ArrayAdapter autoCompleteAdapter = new ArrayAdapter(container.Context, Android.Resource.Layout.SimpleDropDownItem1Line, autoCompleteOptions);            AutoCompleteTextView mautoCompleteTextView = view.FindViewById<AutoCompleteTextView>(Resource.Id.autoCompleteTextView1);            mautoCompleteTextView.Adapter = autoCompleteAdapter;            hozzaadas.Click += hozaadasListViewhez;            hozzaadnivalo = mautoCompleteTextView.Text;        }private void hozaadasListViewhez(object sender, EventArgs e)        {            adapter.Add(mautoCompleteTextView.Text);            adapter.NotifyDataSetChanged();        }所以我想将autocompleteTextView的文本添加到我的listview适配器中,但是我不能在那儿做,因为它在那里不存在。所以我做了一个等于mautoCompleteTextView.Text的字符串,但是它将为空,因为它将在程序启动时在用户未执行任何操作时运行。所以我的问题是,当用户按下按钮时,我无法获得mautoCompleteTextView.Text。如果有人可以阻止,那将非常感谢。
查看完整描述

1 回答

?
杨__羊羊

TA贡献1943条经验 获得超7个赞

您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

    }


查看完整回答
反对 回复 2021-04-24
  • 1 回答
  • 0 关注
  • 197 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号