我创建了一个带有开关和编辑文本字段的表格。我想要发生的事情是当我在同一表格行上的编辑文本字段中输入某个文本时将开关设置为启用所以如果我在编辑文本行中输入文本,如何在第 8 行中设置开关以启用8.
for (int i = 0; i< dbarray_id.size(); i++ )
{
CODE IS HERE TO CREATE A TABLEROW
//Now add a switch to the row
Switch switch1 = new Switch(getActivity());
switch1.setId(i);
switch1.setTag(i);
switch1.setSwitchMinWidth(50);
switch1.setEnabled(false)
//Add a edittext field to the row
final EditText txtaccesscode = new EditText(getActivity());
txtaccesscode.setId(i);
txtaccesscode.setTag(i);
txtaccesscode.setHint("CODE?");
txtaccesscode.setInputType(TYPE_TEXT_FLAG_NO_SUGGESTIONS);
txtaccesscode.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(
....etc... for after change ...
repeat for the number of rows in the database.
因此,当我在任何行中输入文本时,相应的开关就会启用。
谢谢