2013-11-14 25 views
0

我希望我的應用中的ediText字段能夠響應onTextChange事件,以便在文本更改時調用方法。我使用dot42製作應用程序,但只能找到Java中的教程。檢測dot42中的onTextChanged事件

+1

你嘗試過什麼,至少[Google](http://www.google.com) –

+0

是的,我做過。但沒有幫助。如果知道如何做,請分享。 – desolator

+1

[link1](http://stackoverflow.com/questions/7432083/how-to-use-edittext-ontextchanged-event-when-i-press-the-number)和[link2](https:// www .google.co.in/search?q = ontextchange + event + in + android&oq = ontextchange + event + in + android&aqs = chrome..69i57j0l5.6387j0j7&sourceid = chrome&espv = 210&es_sm = 93&ie = UTF-8) –

回答

4

這將是一個最小的實現。我希望它能幫助你看到Java和C#之間的區別模式 - 這實在是微不足道的。

[Activity] 
    public class MainActivity : Activity, Android.Text.ITextWatcher 
    { 
     protected override void OnCreate(Bundle savedInstance) 
     { 
     base.OnCreate(savedInstance); 
     SetContentView(R.Layouts.MainLayout); 

     EditText editText = FindViewById<EditText>(R.Ids.status); 
     editText.AddTextChangedListener(this); 
     } 

     public void AfterTextChanged(Android.Text.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(); 
     } 
    } 

接口實現由Visual Studio生成。

+0

如果有可能,我會給你1000分......我從這個問題的幾個小時 – Blasco73

1

在Java中,你可以通過實現TextWatcher接口來實現。 Dot42 documentation

AddTextChangedListener(ITextWatcher watcher) 

Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.` 

所以實現ITextWatcher,做一些AfterTextChanged,你就OK。

+0

我閱讀了文檔,但沒有幫助。如果你有,請分享示例代碼。 – desolator

+0

我沒有任何示例代碼。你是否按照我的建議去做?你是否用自定義ITextWatcher調用了myTextView.AddTextChangedListener? – Axarydax