Java – Android – Get a list of supported locales

Android – Get a list of supported locales… here is a solution to the problem.

Android – Get a list of supported locales

I have to implement AutoComplete TextView for locales for all supported Android devices. I tried the following:

 public class AutoCompleteView extends Activity{

public void onCreate(Bundle savedInstanceState) {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android. R.layout.simple_dropdown_item_1line, Locales);
    AutoCompleteTextView textView = (AutoCompleteTextView)
static Locale[] locales = Locale.getAvailableLocales();
private static final String[] Locales = ;

I can use Locale[] to get the locale. In the last line of code, how to parse it to String[] Locales: Please help my friend….


Sorry for the late reply

Try this

  Locale[] locales = Locale.getAvailableLocales();
            ArrayList<String> localcountries=new ArrayList<String>();
            for(Locale l:locales)
    String[] languages=(String[]) localcountries.toArray(new String[localcountries.size()]);

Hope this helps.

Related Problems and Solutions