【问题标题】:Editable using reference for a TextChangedListener可使用 TextChangedListener 的参考进行编辑
【发布时间】:2014-03-05 08:04:51
【问题描述】:

在 Xamarin 中,我可以为 EditText 对象的 TextChangedListener 编写一些代码吗?

这是我目前所拥有的:

public class InputTextWatcher
{
    public void afterTextChanged (Editable s)
    {

    }

    public void beforeTextChanged (CharSequence s, int start, int count, int after)
    {

    }

    public void onTextChanged (CharSequence s, int start, int before, int count)
    {

    }
}

这是我得到的错误:

错误 CS0246:找不到类型或命名空间名称“可编辑” (您是否缺少 using 指令或程序集引用?)

【问题讨论】:

    标签: android xamarin textchanged using-directives


    【解决方案1】:

    您需要实现 ITextWatcher:

    using Android.Text;
    
    public class InputTextWatcher : : Java.Lang.Object, ITextWatcher
    {
        public void AfterTextChanged(IEditable s)
        {
            throw new NotImplementedException ();
        }
    
        public void BeforeTextChanged(Java.Lang.ICharSequence s, int start, int count, int after)
        {
            throw new NotImplementedException ();
        }
    
        public void OnTextChanged(Java.Lang.ICharSequence s, int start, int before, int count)
        {
            throw new NotImplementedException ();
        }
    }
    

    您还应该考虑使用事件处理程序:

            editText.BeforeTextChanged += HandleBeforeTextChanged;
    
            // or
            editText.TextChanged += (sender, e) => 
            {
    
            };
        }
    
        void HandleBeforeTextChanged (object sender, TextChangedEventArgs e)
        {
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-20
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多