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

时间:2019-03-19 00:53:04

标签: c# xamarin.android

我想在自动生成的TextInputLayout中放入EditText

示例:如果我单击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);
};

1 个答案:

答案 0 :(得分:1)

TextInputLayout 是22.2.0的新增功能,可与 EditText (或EditText的子类)结合使用,并且只能包含以下子类之一: EditText(或EditText的子类)

您的代码基本上是正确的,您应该这样更改:

B