Reputation: 323
I am stuck in an issue where one of my user entering characters like Ä in an edittext and I am preparing an XML from that data. Due to encoding issue I can't prepare a valid XML from these kind of characters. Is there anyway I can stop user to enter such kind of characters or can I hide these characters from android default keyboard itself ?
Regards
Upvotes: 0
Views: 720
Reputation: 2583
Few days before I was facing same issue I solved this by creating below method.
public static String stripSpecialUTFChars(String string) {
return string.replaceAll("\u0080", "");
}
Please pass your String to above method and use this like below
textView.setText(Html.fromHtml(stripSpecialUTFChars(yourString)));
actually this issue is due to UTF characters.
Upvotes: -1
Reputation: 1909
you can restrict the user to enter only specific characters in the edit text like below,
<EditText
android:id="@+id/YourEdittextId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:privateImeOptions="nm"
android:digits="0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" />
Above code restrict user to enter only English digits, letters and space
Upvotes: 2
Reputation: 1971
Hide suggestion string in your edittext.
android:inputType="textFilter"
Upvotes: 0