Using list preference in Android

后端 未结 3 1736
-上瘾入骨i
-上瘾入骨i 2020-12-24 13:09

I have a text to speech application where the user can select a language and also select a male or female voice. The problem is that for each language there are different st

3条回答
  •  爱一瞬间的悲伤
    2020-12-24 13:38

    Sorry, I'm not able to comment on an answer yet, so I open a new one.

    Instead of writing your own algorithm in order to find the index of a particular item in a String array just rely on the standard API (it's usually faster, better design and just shorter):

    final int a = Arrays.binarySearch(languageAlias, languageData);
    

    It's the same as :

    int a = 0
    
    for (a ; a < languageAlias.length ; a++) {
        if (languageAlias[a].equals(languageData) {
            break;
        }
    }
    

提交回复
热议问题