2014-09-08 10 views
11

voglio fare il mio EditText come quando scrivo carattere "g" è legato mappatura carattere personalizzato dovrebbe scritto come qui in Hindi E ' "जी"mappatura dei caratteri in EditText Android

penso che ci dovrebbe essere la mappatura carattere ma avere nessuna conoscenza qualcuno mi può aiutare come fare

altra applicazione https://play.google.com/store/apps/details?id=nichetech.hindi.editor è anche facendo lo stesso come in questo modo, non v'è opzione disponibile offline e online

online sta facendo con l'aiuto di Google translator, ma se scelgo offline quindi la scrittura avviene in questo modo

Qui si può vedere che la tastiera è l'inglese, ma la scrittura è fatto in lingua hindi

enter image description here

Grazie

C'è modo che scrivo in inglese e il suo carattere mappatura correlate sarà scritto in Modifica il testo della mia sola applicazione.

Qualcuno fatto come questo senso allora per favore mi aiuti, come fare

+0

se ho capito bene, allora si può fare Map per le lettere della tastiera e le lettere di destinazione, quindi sostituisci onKeyUp() o r onKeyDown() e carattere replacce su editText .... controlla questo https://developer.android.com/training/keyboard-input/commands.html – Yazan

risposta

7

per realizzare quello che stai dopo, vorrei creare un HashMap di caratteri che mappano ad altri caratteri. Se alcuni caratteri specifici non sono mappati, basta stamparli. Ecco un esempio che ho messo su:

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) { 

    } 
}); 

Pro:

  • Ignora caso quando alla ricerca di un sostituto. (Q = Q = 1)
  • Sostituisce immediatamente singola e multipla caratteri
  • Sono esclusi anello l'intera stringa
  • può sostituire nel mezzo di un'altra stringa

Contro:

  • È necessario disporre di una voce HashMap per ogni carattere che si desidera sostituire
  • ...

Come un lato nota vorrei citarne alcune limitazioni che "versione online" la tua data di applicazione è:

  • La conversione avviene solo quando uno spazio, nuova linea o segno di punteggiatura inserito.
  • Non è possibile aggiungere lettere a parole già convertite.

La versione applicazioni "offline" ha anche un bug minore:

  • Non converte le parole che vengono copiati o scritti con Swipe
+0

Ciao Grazie per la tua risposta, ma sto parlando della modalità OFFLINE, in Modalità offline, il carattere è in fase di conversione nello stesso momento in cui digito, non lo spazio –

+0

@SiddhpuraAmit L'app che hai assegnato non funziona affatto in modalità offline. Tuttavia il mio esempio funzionerà indipendentemente dalla connessione Internet. – Simas

+0

Ciao C'è un menu a scorrimento in cui sceglierai prima offline e dopo potrai farlo, sta funzionando bene sul mio telefono, ma non in genimotion –

0

Credo che si sta meglio cercando di creare il proprio file * .ttf con tutti i mapping di caratteri. Puoi semplicemente impostarlo sul tuo EditText (o qualunque altro widget di testo tu stia usando). I font TTF sono benvenuti in assets/directory (o qualsiasi directory da cui si può leggere). È possibile creare l'oggetto Carattere con:

Typeface.createFromAsset(AssetManager mgr, String path)

e l'impostazione con:

textView.setTypeface(mTypeface); 
0

file mappa personaggio chiave (file .kcm) sono responsabili per le combinazioni di mappatura di codici chiave Android con modificatori Unicode caratteri.I file di layout chiave specifici per il dispositivo sono necessari per tutti i dispositivi di input interni (incorporati) che dispongono di chiavi, se non altro per comunicare al sistema che il dispositivo ha uno scopo speciale (non una tastiera completa).

I file di layout delle chiavi specifici del dispositivo sono opzionali per le tastiere esterne e spesso non sono affatto necessari. Il sistema fornisce una mappa di caratteri chiave generica adatta per molte tastiere esterne.

Se non è disponibile un file di layout chiave specifico per dispositivo, il sistema sceglierà un valore predefinito.

I file di mappe dei caratteri chiave sono localizzati dal fornitore USB, dal prodotto (e facoltativamente dalla versione) id o dal nome del dispositivo di input.

I file di mappe dei caratteri chiave sono localizzati dal fornitore USB, dal prodotto (e facoltativamente dalla versione) id o dal nome del dispositivo di input.

Supponiamo che l'utente abbia premuto A e SHIFT insieme. Il sistema individua innanzitutto l'insieme di proprietà e comportamenti associati a KEYCODE_A.

tasto A { label: 'A' di base: 'a' spostamento, capslock: 'A' ctrl, alt, meta: nessuno }

ey ESCAPE { di base: fallback INDIETRO alt, meta: HOME fallback ctrl: MENU fallback }

tasto A { label: 'A' numero: '2' Base: 'a' spostamento, capslock: 'A' alt: '#' Shift + Alt, capslock + ALT: nessuno }

tasto SPACE { etichetta: '' numero: '' di base : '' spostamento: '' alt: '\ uef01' Shift + alt: '\ uef01' }

0
public void MapCharacter() { 
    this.singleChar.put((Object)"a", (Object)"\u0905"); 
    this.singleChar.put((Object)"b", (Object)"\u092c"); 
    this.singleChar.put((Object)"c", (Object)"\u091a"); 
    this.singleChar.put((Object)"d", (Object)"\u0926"); 
    this.singleChar.put((Object)"e", (Object)"\u090f"); 
    this.singleChar.put((Object)"f", (Object)"\u092b"); 
    this.singleChar.put((Object)"g", (Object)"\u0917"); 
    this.singleChar.put((Object)"h", (Object)"\u0939"); 
    this.singleChar.put((Object)"i", (Object)"\u0907"); 
    this.singleChar.put((Object)"j", (Object)"\u091c"); 
    this.singleChar.put((Object)"k", (Object)"\u0915"); 
    this.singleChar.put((Object)"l", (Object)"\u0932"); 
    this.singleChar.put((Object)"m", (Object)"\u092e"); 
    this.singleChar.put((Object)"n", (Object)"\u0928"); 
    this.singleChar.put((Object)"o", (Object)"\u0913"); 
    this.singleChar.put((Object)"p", (Object)"\u092a"); 
    this.singleChar.put((Object)"q", (Object)""); 
    this.singleChar.put((Object)"r", (Object)"\u0930"); 
    this.singleChar.put((Object)"s", (Object)"\u0938"); 
    this.singleChar.put((Object)"t", (Object)"\u0924"); 
    this.singleChar.put((Object)"u", (Object)"\u0909"); 
    this.singleChar.put((Object)"v", (Object)"\u0935"); 
    this.singleChar.put((Object)"w", (Object)"\u0935"); 
    this.singleChar.put((Object)"x", (Object)"\u0915\u094d\u0937"); 
    this.singleChar.put((Object)"y", (Object)"\u092f"); 
    this.singleChar.put((Object)"z", (Object)"\u091d"); 
    this.singleChar.put((Object)"A", (Object)"\u0906"); 
    this.singleChar.put((Object)"B", (Object)"\u092c"); 
    this.singleChar.put((Object)"C", (Object)"\u091a"); 
    this.singleChar.put((Object)"D", (Object)"\u0921"); 
    this.singleChar.put((Object)"E", (Object)"\u090d"); 
    this.singleChar.put((Object)"F", (Object)"\u092b"); 
    this.singleChar.put((Object)"G", (Object)"\u0917"); 
    this.singleChar.put((Object)"H", (Object)"\u0903"); 
    this.singleChar.put((Object)"I", (Object)"\u0908"); 
    this.singleChar.put((Object)"J", (Object)"\u091c"); 
    this.singleChar.put((Object)"K", (Object)"\u0915"); 
    this.singleChar.put((Object)"L", (Object)"\u0933"); 
    this.singleChar.put((Object)"M", (Object)"\u0902"); 
    this.singleChar.put((Object)"N", (Object)"\u0923"); 
    this.singleChar.put((Object)"O", (Object)"\u0911"); 
    this.singleChar.put((Object)"P", (Object)"\u092a"); 
    this.singleChar.put((Object)"Q", (Object)""); 
    this.singleChar.put((Object)"R", (Object)"\u0930"); 
    this.singleChar.put((Object)"S", (Object)"\u0936"); 
    this.singleChar.put((Object)"T", (Object)"\u091f"); 
    this.singleChar.put((Object)"U", (Object)"\u090a"); 
    this.singleChar.put((Object)"V", (Object)"\u0935"); 
    this.singleChar.put((Object)"W", (Object)"\u0935"); 
    this.singleChar.put((Object)"X", (Object)"\u0915\u094d\u0937"); 
    this.singleChar.put((Object)"Y", (Object)"\u092f"); 
    this.singleChar.put((Object)"Z", (Object)"\u091d"); 
    this.singleChar.put((Object)"1", (Object)"\u0967"); 
    this.singleChar.put((Object)"2", (Object)"\u0968"); 
    this.singleChar.put((Object)"3", (Object)"\u0969"); 
    this.singleChar.put((Object)"4", (Object)"\u096a"); 
    this.singleChar.put((Object)"5", (Object)"\u096b"); 
    this.singleChar.put((Object)"6", (Object)"\u096c"); 
    this.singleChar.put((Object)"7", (Object)"\u096d"); 
    this.singleChar.put((Object)"8", (Object)"\u096e"); 
    this.singleChar.put((Object)"9", (Object)"\u096f"); 
    this.singleChar.put((Object)"0", (Object)"\u0966"); 
    this.singleChar.put((Object)"#", (Object)"\u0953"); 
    this.singleChar.put((Object)"$", (Object)" \u0951"); 
    this.singleChar.put((Object)"^", (Object)"\u094d"); 
    this.singleChar.put((Object)":", (Object)"\u0903"); 
    this.delimtrChar.put((Object)" ", (Object)" "); 
    this.delimtrChar.put((Object)"!", (Object)"!"); 
    this.delimtrChar.put((Object)"@", (Object)"\u0970"); 
    this.delimtrChar.put((Object)"%", (Object)"%"); 
    this.delimtrChar.put((Object)"&", (Object)"\u093d"); 
    this.delimtrChar.put((Object)"(", (Object)"("); 
    this.delimtrChar.put((Object)")", (Object)")"); 
    this.delimtrChar.put((Object)"~", (Object)"~"); 
    this.delimtrChar.put((Object)"`", (Object)"`"); 
    this.delimtrChar.put((Object)"_", (Object)"_"); 
    this.delimtrChar.put((Object)"=", (Object)"="); 
    this.delimtrChar.put((Object)"{", (Object)"{"); 
    this.delimtrChar.put((Object)"}", (Object)"}"); 
    this.delimtrChar.put((Object)"|", (Object)"\u0964"); 
    this.delimtrChar.put((Object)"\"", (Object)"\""); 
    this.delimtrChar.put((Object)"<", (Object)"<"); 
    this.delimtrChar.put((Object)">", (Object)">"); 
    this.delimtrChar.put((Object)"?", (Object)"?"); 
    this.delimtrChar.put((Object)"+", (Object)"+"); 
    this.delimtrChar.put((Object)"-", (Object)"-"); 
    this.delimtrChar.put((Object)"[", (Object)"["); 
    this.delimtrChar.put((Object)"]", (Object)"]"); 
    this.delimtrChar.put((Object)"\\", (Object)"\\"); 
    this.delimtrChar.put((Object)";", (Object)";"); 
    this.delimtrChar.put((Object)"'", (Object)"'"); 
    this.delimtrChar.put((Object)",", (Object)","); 
    this.delimtrChar.put((Object)".", (Object)"."); 
    this.delimtrChar.put((Object)"/", (Object)"/"); 
    this.doubleChar.put((Object)"aa", (Object)"\u0906"); 
    this.doubleChar.put((Object)"ai", (Object)"\u0910"); 
    this.doubleChar.put((Object)"au", (Object)"\u0914"); 
    this.doubleChar.put((Object)"ou", (Object)"\u0914"); 
    this.doubleChar.put((Object)"ee", (Object)"\u0908"); 
    this.doubleChar.put((Object)"oo", (Object)"\u090a"); 
    this.doubleChar.put((Object)"aM", (Object)"\u0905\u0902"); 
    this.doubleChar.put((Object)"aM~", (Object)"\u0905\u0901"); 
    this.doubleChar.put((Object)"aH", (Object)"\u0905\u0903"); 
    this.doubleChar.put((Object)"a:", (Object)"\u0905\u0903"); 
    this.doubleChar.put((Object)"NG", (Object)"\u0919"); 
    this.doubleChar.put((Object)"OM", (Object)"\u0950"); 
    this.doubleChar.put((Object)"+~", (Object)"\u5350"); 
    this.doubleChar.put((Object)"Rs", (Object)"\u20b9"); 
    this.doubleChar.put((Object)"||", (Object)"\u0965"); 
    this.doubleChar.put((Object)"NY", (Object)"\u091e"); 
    this.doubleChar.put((Object)"Gy", (Object)"\u091c\u094d\u091e"); 
    this.doubleChar.put((Object)"kh", (Object)"\u0916"); 
    this.doubleChar.put((Object)"gh", (Object)"\u0918"); 
    this.doubleChar.put((Object)"Ch", (Object)"\u091b"); 
    this.doubleChar.put((Object)"chh", (Object)"\u091b"); 
    this.doubleChar.put((Object)"ch", (Object)"\u091a"); 
    this.doubleChar.put((Object)"th", (Object)"\u0925"); 
    this.doubleChar.put((Object)"Th", (Object)"\u0920"); 
    this.doubleChar.put((Object)"dh", (Object)"\u0927"); 
    this.doubleChar.put((Object)"Dh", (Object)"\u0922"); 
    this.doubleChar.put((Object)"jh", (Object)"\u091d"); 
    this.doubleChar.put((Object)"ph", (Object)"\u092b"); 
    this.doubleChar.put((Object)"bh", (Object)"\u092d"); 
    this.doubleChar.put((Object)"sh", (Object)"\u0936"); 
    this.doubleChar.put((Object)"Sh", (Object)"\u0937"); 
    this.doubleChar.put((Object)"kSh", (Object)"\u0915\u094d\u0937"); 
    this.doubleChar.put((Object)"Ri", (Object)"\u090b"); 
    this.doubleChar.put((Object)"RI", (Object)"\u0960"); 
    this.doubleChar.put((Object)"Li~", (Object)"\u090c"); 
    this.doubleChar.put((Object)"LI~", (Object)"\u0961"); 
    this.doubleChar.put((Object)"@@", (Object)"\u0971"); 
    this.doubleChar.put((Object)"$$", (Object)"\u0952"); 
    this.matraChar.put((Object)"a", (Object)"\u093e"); 
    this.matraChar.put((Object)"A", (Object)"\u093e"); 
    this.matraChar.put((Object)"i", (Object)"\u093f"); 
    this.matraChar.put((Object)"I", (Object)"\u0940"); 
    this.matraChar.put((Object)"u", (Object)"\u0941"); 
    this.matraChar.put((Object)"U", (Object)"\u0942"); 
    this.matraChar.put((Object)"e", (Object)"\u0947"); 
    this.matraChar.put((Object)"E", (Object)"\u0945"); 
    this.matraChar.put((Object)"o", (Object)"\u094b"); 
    this.matraChar.put((Object)"O", (Object)"\u0949"); 
    this.matraChar.put((Object)"ai", (Object)"\u0948"); 
    this.matraChar.put((Object)"au", (Object)"\u094c"); 
    this.matraChar.put((Object)"ou", (Object)"\u094c"); 
    this.matraChar.put((Object)"aa", (Object)"\u093e"); 
    this.matraChar.put((Object)"oo", (Object)"\u0942"); 
    this.matraChar.put((Object)"ee", (Object)"\u0940"); 
    this.matraChar.put((Object)"*", (Object)"\u093c"); 
    this.matraChar.put((Object)"M~", (Object)"\u0901"); 
    this.matraChar.put((Object)"r", (Object)"\u094d\u0930"); 
    this.matraChar.put((Object)"R", (Object)"\u0930\u094d"); 
    this.matraChar.put((Object)"Ri", (Object)"\u0943"); 
    this.matraChar.put((Object)"RI", (Object)"\u0944"); 
    this.matraChar.put((Object)"Li~", (Object)"\u0962"); 
    this.matraChar.put((Object)"LI~", (Object)"\u0963"); 
}