I want to make my edittext like when I write character "g" it's related mapping custom character should written like here in Hindi it's "जी"
I think there should be character mapping but having no knowledge can anybody help me how to do that
Other app https://play.google.com/store/apps/details?id=nichetech.hindi.editor is also doing same like this way, there is option available offline and online
Online is doing with help of google translator but if I choose Offline then writing happen like this way
Here you can see that Keyboard is English, but writing is done in Hindi language
Thanks
Is there way that I write in English and it's related mapping character will written in EditText of my application only.
Does anybody done like this way then please help me, how to do that
To accomplish what you're after, I would create a HashMap of chars that map to other chars. If some specific char is not mapped just print it out. Here's an example I've put up:
final HashMap<Character, Character> charMap = new HashMap<Character, Character>();
charMap.put('q', '1');
charMap.put('w', '2');
charMap.put('e', '3');
charMap.put('r', '4');
charMap.put('t', '5');
charMap.put('y', '6');
final EditText editText = (EditText) findViewById(R.id.editText);
editText.addTextChangedListener(new TextWatcher() {
boolean replaced;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.e("TAG", start + " " + before + " " + count);
// Check in lower case
String oldStr = s.toString().toLowerCase();
StringBuilder newStr = new StringBuilder(s);
// Loop through changed chars
for (int i = 0; i < count; i++) {
// Replace if a substitution is avaiable
Character replacement = charMap.get(oldStr.charAt(start + i));
if (replacement != null) {
replaced = true;
newStr.setCharAt(start + i, replacement);
}
}
if (replaced) {
replaced = false;
editText.setText(newStr);
// Move cursor after the new chars
editText.setSelection(start + count);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Pros:
Cons:
As a side-note I'd like to name a few limitations that your given app's "online version" has:
The apps "offline" version also has a minor bug:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With