8

I have an EditText with restricted characters. I allow digits only as

A strange thing appears on a Galaxy S4. It didn't appear a HTC Desire HD, HTC Desire X and a ZTE Blade.

  1. I type dddsss
  2. I type a swedish character like å.
  3. It's not appearing as it is not an allowed character, so the content is still dddsss
  4. I type a character, e.g. u
  5. The content of the EditText becomes dddsssdddsssu
  6. I type another character, e.g. t and the content becomes dddsssdddsssudddsssut

It sometimes happens when I press the backspace as well, so it must be a button press issue.

I added android:inputType="textNoSuggestions" but it didn't help.

<EditText
      android:id="@+id/comment_et"
      android:layout_width="0dp"
      android:layout_height="45dp"
      android:layout_marginRight="5dp"
      android:layout_weight="1"
      android:paddingLeft="5dp"
      android:paddingRight="5dp"
      android:background="@drawable/idea_edittext"
      android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ,0,1,2,3,4,5,6,7,8,9,*,!,@,#,$,%,^,(,),_,+,-,[,],{,},:,;,&apos;,|,\,.,/,ß,?,~,="
      android:inputType="textCapSentences|textNoSuggestions"
      android:textSize="16dp" />

Has anyone experienced this?

erdomester
  • 11,789
  • 32
  • 132
  • 234
  • No, it's a bug with many Samsung devices, including yours. It seems to affect some Latin extended characters like "ư", "ơ", "å", etc, so when you type these characters in an `EditText`, you'll get nothing returned. – ChuongPham Apr 26 '14 at 12:55
  • You misunderstood. Those characters are not returned because they are restricted with the `digits` attribute. The problem is what I typed before is duplicated after typing these characters – erdomester Apr 26 '14 at 13:11
  • Maybe this [link](http://stackoverflow.com/questions/3349121/how-do-i-use-inputfilter-to-limit-characters-in-an-edittext-in-android?rq=1) (found under **Related** on the right of the post) might help. – ChuongPham Apr 26 '14 at 13:19
  • did you find a solution for this problem? i have same. thanks. – savepopulation Mar 04 '15 at 12:22
  • Sorry I don't remember how I solved this – erdomester Mar 04 '15 at 18:59

2 Answers2

3

I have same problem and solved with changing EditText's inputtype to:

android:inputType="text|textNoSuggestions"

I don't know if it's a proper solution but it's ok for me.

savepopulation
  • 11,736
  • 4
  • 55
  • 80
0

Personally, changing the EditText's inputtype to:

android:inputType="text|textNoSuggestions"

did not work. But I noticed that the content duplication does not occur anymore when the back key is pressed. I know this is probably not a right way to solve the problem, but awaiting a real solution, and if it can help some people, I did a little trick on my EditText to solve the problem :

 private string formerText = null;
 private bool isEditLocked = false;

 editText.TextChanged += (sender, e) =>
            {
                if (!isEditLocked)
                {
                    var currentSelection = editText.SelectionStart;
                    isEditLocked = true;
                    if (formerText != null && editText.Text == formerText)
                    {
                        if (editText.Text.Length == 0)
                        {
                            editText.Text = "";
                        }
                        else
                        {
                            var lastChar = editText.Text[editText.Text.Length - 1];
                            editText.Text = editText.Text.Remove(editText.Text.Length - 1);
                            editText.Text += lastChar;
                        }
                    }
                    formerText = editText.Text;
                    editText.SetSelection(currentSelection);
                    isEditLocked = false;
                }
            };

As you can see, I just programmatically remove the last char of my EditText, then add it again, and then the duplication problem is gone.

Note that this is Xamarin.Android code, so this is written is C#, but you should be able to convert it into Java quite easily (editText.Text = ... becomes editText.setText(...) and so on).

Please, if someone find a REAL solution to this problem, post it there, because it still happens in semtember 2017