亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在單擊按鈕時獲取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 關注
  • 205 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號