我想把TextInputLayout
放在我自动生成的EditText
中。
示例:如果我单击Button
,该应用程序将生成Spinner
和EditText
,我想在我的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);
};