我正在编写一些逻辑,其中EditText视图有一个监听器,它监听文本的长度以匹配12个字符。在某个阶段,用户可以返回到此阶段,该阶段将使用12个字符的值填充EditText作为文本,而不是提示(需要是文本)。
我的问题是用户可以回来将他的标签输入相关的条形码,但条形码会被填充到条形码EditText中。
最好的选择是一次填写EditText,删除侦听器并在之后再次附加它吗?
详细说明:
条形码始终为12位数。技术人员将有两个输入,一个标签和一个条形码。他可以输入条形码而不输入标签以继续。当技术人员回来输入他的标签时,条形码会被填充,从而开始活动。如何在不启动事件的情况下填充条形码?
barcode.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) =>
{
if (e.Text.ToString().Length == 12)
{
if (SampleState.Instance.doesBarcodeExist(long.Parse(barcode.Text), Row))
{
Toast.MakeText(this.Activity, "That Barcode is already Associated to an Animal", ToastLength.Short).Show();
}
// Technician has both the animal number and barcode.
else if (animalTagText.Text.Length > 0 && barcode.Text.Length > 0)
{
tagText = animalTagText.Text;
barcodeText = barcode.Text;
this.commitAndClean();
}
// Technician only has the barcode available.
else if (animalTagText.Text.Length <= 0 && barcode.Text.Length > 0)
{
tagText = animalTagText.Text;
barcodeText = barcode.Text;
animalTagText.RequestFocus();
}
}
};
...
try {
if (SampleState.Instance.getSamples(Row).ElementAt(i).Skipped == true)
{
unitText.Text = SampleState.Instance.getSamples(Row).ElementAt(i).Unit.ToString();
animalTagText.Text = SampleState.Instance.getSamples(Row).ElementAt(i).Tag;
// This is filling the Barcode EditText after it was skipped which kicks off the event. Trying to stop this.
barcode.Text = SampleState.Instance.getSamples(Row).ElementAt(i).BarCode.ToString();
rowText.Text = SampleState.Instance.getSamples(Row).ElementAt(i).Row.ToString();
}
else if (i + 1 == SampleState.Instance.getSamples(Row).Count)
{
this.finshedSampling();
}
}
由于