EditText.getText() isn't bound
- Dominant language
- C#
- Stars
- 2.1k
- Forks
- 579
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 257
Description
### 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:
> When calling `EditText.setText()` on android, it resets the keyboard. This is super annoying if you are processing inputs and the user changes from ABC view to symbols view, the keyboard jumps 'back' to ABC view.
> …
> The 'workaround' natively is to not call `SetText` and instead call `getText().Clear()` and then `getText().Append(blah)`
The problem is, that's not currently possible, because there is no `Text` or `TextFormatted` property that has a `.Clear()` method. The [`TextView.TextFormatted` property](https://learn.microsoft.com/en-us/dotnet/api/android.widget.textview.textformatted?view=net-android-34.0) returns [`ICharSequence`](https://learn.microsoft.com/en-us/dotnet/api/java.lang.icharsequence?view=net-android-34.0), which has no `Clear()` method.
What's Going On?
What's going on is our favorite, covariant return types: [`TextView.getText()`](https://developer.android.com/reference/android/widget/TextView#getText()) returns `CharSequence`, while [`EditText.getText()`](https://developer.android.com/reference/android/widget/EditText#getText()) returns the [`Editable` interface](https://developer.android.com/reference/android/text/Editable.html). However, C# covariant return types only works for *classes*, not interfaces, and regardless we don't re-bind the `Text` property on `EditText`.
## Proposal
Use `src/Mono.Android/metadata` to bind the `EditText.getText()` method as the `EditText.TextEditable` property. That would allow the original customer to call `myEditText.TextEditable.Clear()`, which is not currently possible.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.