-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EditText.getText() isn't bound #9192
Comments
One issue is that % grep 'getText.*Editable' src/Mono.Android/Profiles/api-35.xml
# no match :shocked-pikachu-face: I then remember this comment from java-interop#1239, where I recreated the API.xml for % dotnet bin/Debug-net8.0/class-parse.dll ~/android-toolchain/sdk/platforms/android-35/android.jar > android-35.xml
% xpath -e '//class[method[@name="getText" and contains(@return, "Editable")]]/@jni-signature' android-35.xml
Found 1 nodes in android-35.xml:
-- NODE --
jni-signature="Landroid/widget/EditText;" For starters, this means this isn't a simple metadata fix, as metadata requires that the method already be within Secondly, this re-ups my query elsewhere about how we're generating |
Apropos of nothing is the documentation for
There are two "minor" problems with that comment:
Consider the hypothetical binding for a /* 1 */ partial class EditText {
/* 2 */ public unsafe Android.Text.IEditable? TextEditable {
/* 3 */ [Register ("getText", "()Landroid/text/Editable;", "GetGetTextHandler")]
/* 4 */ get {
/* 5 */ const string __id = "getText.()Landroid/text/Editable;";
/* 6 */ try {
/* 7 */ var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null);
/* 8 */ return global::Java.Lang.Object.GetObject<Android.Text.IEditable> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
/* 9 */ } finally {
/* 10 */ }
/* 11 */ }
/* 12 */ }
/* 13 */ } Line 8 may throw if the value returned is a
It might be fine! It might not! Which doesn't make me feel good. Fortunately the workaround is straightforward: use var scannable = edittext.TextFormatted.JavaCast<ISpannable>(); |
Because of "missing methods", there is now an implicit audit of |
Workaround (?) to invoke var editable = editText.TextFormatted.JavaCast<Android.Text.IEditable>();
editable.Clear();
editable.Append(…); |
Android framework version
net8.0-android, net9.0-android
Affected platform version
.NET 8.0
Description
Context: https://discord.com/channels/732297728826277939/732297837953679412/1272467705534091348
Context: https://stackoverflow.com/questions/26365808/edittext-settext-changes-the-keyboard-type-to-default-from-123-to-abc
Background
A customer came onto Discord asking:
The problem is, that's not currently possible, because there is no
Text
orTextFormatted
property that has a.Clear()
method. TheTextView.TextFormatted
property returnsICharSequence
, which has noClear()
method.What's Going On?
What's going on is our favorite, covariant return types:
TextView.getText()
returnsCharSequence
, whileEditText.getText()
returns theEditable
interface. However, C# covariant return types only works for classes, not interfaces, and regardless we don't re-bind theText
property onEditText
.Proposal
Use
src/Mono.Android/metadata
to bind theEditText.getText()
method as theEditText.TextEditable
property. That would allow the original customer to callmyEditText.TextEditable.Clear()
, which is not currently possible.The text was updated successfully, but these errors were encountered: