Android – how to get the text language in textview?

I have a textview in the Android messaging application. I receive messages from my Android phone and display them in textviews. If the text is Persian, I want to change the layout_ If gravity is set to correct, how do I detect the text language obtained from the following URIs?

Uri uri = Uri.parse("content://sms/");

resolvent:

There are bidi classes. This class has the getbaselevel () method. If your text is from left to right, it returns 0, otherwise it returns 1 (if from right to left)

Example:

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        Bidi bidi = new Bidi(userList.get(position).getName(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
        if(bidi.getBaseLevel() == 0)
            convertView = myInflater.inflate(R.layout.list_add_friends_row, null);
        else
            convertView = myInflater.inflate(R.layout.list_add_friends_row_mirror, null);

There is another method baseislefttoright(), which may be best used in if statements. The result is the same as above

Bidi bidi = new Bidi(userList.get(position).getName(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
if(bidi.baseIsLeftToRight())
                convertView = myInflater.inflate(R.layout.list_add_friends_row, null);
            else
                convertView = myInflater.inflate(R.layout.list_add_friends_row_mirror, null);

SRC: https://stackoverflow.com/a/18008575/797495

public final class Bidi
extends Object

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>