Reputation: 11829
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.
dddsss
å
.dddsss
u
dddsssdddsssu
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,*,!,@,#,$,%,^,(,),_,+,-,[,],{,},:,;,',|,\,.,/,ß,?,~,="
android:inputType="textCapSentences|textNoSuggestions"
android:textSize="16dp" />
Has anyone experienced this?
Upvotes: 8
Views: 1799
Reputation: 453
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
Upvotes: 0
Reputation: 11921
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.
Upvotes: 3