Create an event to intercept a key pressed on Android ( OnTextChangedListener undefined )

I have some EditTexts on my android app to get float numbers, I need to use a numeric keypad and I am using android:inputType=“phone” on the layout-xml, so this gave me the phone keyboard, but to access the “.” the user must do an extra step to get it.

Before I start to create a custom keyboard ( I got some tutorials about this ), I want to try to replace the “*” to “.”, so I could try this solution.

Public
method afterTextChanged(s: android.text.Editable);

implementation

method RomaneioEntProdutosItens.afterTextChanged(s: android.text.Editable);
begin
var doubleValue: Double := 0;
if (s <> nil) then begin
try
doubleValue := Double.parseDouble(s.toString().replace(’*’, ‘.’));
except

end
end
end;

var edtLarg: EditText := EditText(findViewById(R.id.ed_largura));
edtLarg.OnTextChangedListener := new interface EditText.OnTextChangedListener( OnTextChangedListener := @afterTextChanged );

I am having this error on the last line above.

Error 13 (E28) Unknown type “EditText.OnTextChangedListener” RomaneioEntProdutosItens.pas 118 50 Absolut.coletor.producao

I think it should by edtLarg.addTextChangedListener( );

Any idea?

Thanks in advance,

José Carlos.

According to Android API refference here, we need to provide a TextWatcher’s interface implementation to handle view’s text changes.
The point you should keep in mind is that Oxygene doesn’t change platform API. Therefore, if Android forced you to provide TextWatcher implementation, you would be true for both pure Java and Oxygene languages.
Back to your case, we can change your code in that way:

var edtLarg: EditText := EditText(findViewById(R.id.ed_largura));
edtLarg.addTextChangedListener(new interface android.text.TextWatcher(
  afterTextChanged := method(s: android.text.Editable)
  begin
     // your code goes here
  end));

As you may have already noticed, you don’t need to provide code for methods of TextWatcher interface. Oxygene will provide empty methods’ implementations for you, so you won’t need to be bothered about useless code lines in you sources.

I got it working, Thanks.