EditText.getText() isn't bound

Open Beginner friendly
#9,192 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
android, csharp
Domain
mobile-dev

Research direction

Start in src/Mono.Android/metadata and inspect how EditText and TextView members are represented in the binding metadata. Confirm that EditText.getText() is exposed as an editable TextEditable property, allowing Clear() and Append() while preserving the requested behavior.

Written by the indexing model from the issue text.

Description

Area: Mono.Android
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 returns ICharSequence, which has no Clear() method.

What's Going On?

What's going on is our favorite, covariant return types: TextView.getText() returns CharSequence, while EditText.getText() returns the Editable interface. 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.

Dominant language
C#
Stars
2.1k
Forks
580
Avg merge
2d 19m
Merged PRs (30d)
228

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/android

All issues in dotnet/android

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.