簡體   English   中英

如何在我自動生成的edittext中以編程方式放置textinputlayout

[英]how to put a textinputlayout programmatically in my auto generated edittext

我想在自動生成的EditText放置一個TextInputLayout

示例:如果單擊Button ,則應用程序將生成SpinnerEditText並且我想將TextInputLayout放在我的EditText

btn.Click += (sender, e) =>
{
    tr = new TableRow(this);
    _spinner = new Spinner(this);
    _td1 = new EditText(this);
    _td2 = new EditText(this);
    TextInputLayout textInputLayout = new TextInputLayout(this);
    _td1.SetHint(Resource.String.qty);
    _td2.SetHint(Resource.String.unit);
    //textInputLayout.AddView(_td1);
    //textInputLayout.AddView(_td2);
    //_td1.SetBackgroundResource(Resource.Drawable.EditDesign);
    //_td2.SetBackgroundResource(Resource.Drawable.EditDesign);
    //_spinner.SetBackgroundResource(Resource.Drawable.EditTxtStyle);
    ArrayAdapter<string> _adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, prodList);
    _spinner.Adapter = _adapter;
    tr.AddView(textInputLayout);
    tr.AddView(_spinner);
    tr.AddView(_td1);
    tr.AddView(_td2);
    tbleLayout.AddView(tr);
};

TextInputLayout是22.2.0的新增功能,可與EditText (或EditText的子類)結合使用,並且只能包含EditText的一個子類(或EditText的子類)

您的代碼基本上是正確的,您應該這樣更改:

 button.Click += (sender, e) =>
     {
         tr = new TableRow(this);
         _spinner = new Spinner(this);
         _td1 = new EditText(this);
         _td2 = new EditText(this);
         TextInputLayout textInputLayout1 = new TextInputLayout(this);
         TextInputLayout textInputLayout2 = new TextInputLayout(this);
         _td1.SetHint(Resource.String.qty);
         _td2.SetHint(Resource.String.unit);
        ArrayAdapter<string> _adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, prodList);
        _spinner.Adapter = _adapter;
        textInputLayout1.AddView(_td1);
        textInputLayout2.AddView(_td2);
        tr.AddView(textInputLayout);
        tr.AddView(_spinner);
        tbleLayout.AddView(tr);
    };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM