2014-03-05 37 views
0

在Xamarin中,我可以爲EditText對象的TextChangedListener編寫一些代碼嗎?使用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:類型或命名空間名稱「編輯」找不到 (您是否缺少使用指令或裝配參考?)

回答

0

您需要實施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) 
    { 

    }