2017-02-13 5 views
2

説明を取得するためのEditTextがあり、最大長を145文字に設定したいと思います。 XMLでmaxlength 145を設定しました。これは英語で正しく動作します。 しかし、英語以外の言語、具体的には、Marathi、Hindiなどでは正しく動作しません。私はそれぞれの記号を別個の文字として数えます。例えばアンドロイドのユニコード文字列(Hindi/Marathi)で文字をカウントする方法

:「व्ही」

これはヒンディー語で一つの文字とみなされ、それの長さは1でなければなりませんが、それは私がthis link

溶液を見てきた長さ2

を私に返します

しかし、接続された文字を検出できないため、ヒンディー語/マラーティー語では機能しません。接続された文字を検出する方法は?事前に

感謝:)

答えて

0

Plzはこのお試しください

String str = "व्ही"; 
int count = 0; 

for(int i=0; i<str.length(); i++) 
{ 
    if(!isMark(str.charAt(i))) 
     count++; 
} 

textview.setText(count); 
0

このコードを試してみてください。それは書記素クラスタと呼ぶものに

UnicodeのFAQ:

import java.text.BreakIterator; 
import java.util.Locale; 

public class MyClass { 

    private int graphemeClusterCount(Locale locale) { 

     String text = "व्ही"; 

     BreakIterator breakIterator = BreakIterator.getCharacterInstance(locale); 

     breakIterator.setText(text); 

     int count = 0; 

     int start = breakIterator.first(); 
     for (int end = breakIterator.next(); 
      end != BreakIterator.DONE; 
      start = end, end = breakIterator.next()) { 

      count++; 
     } 

     return count; 
    } 
} 

いくつかの参照を。 http://unicode.org/faq/char_combmark.html#7

Androidのドキュメントから10

サンプルコードは:http://site.icu-project.org/あなたはGradleの中にインポートすることができます:https://developer.android.com/reference/java/text/BreakIterator.html

ICUも、BreakIterator実装を持っている

compile 'com.ibm.icu:icu4j:58.2' 
関連する問題